Search Issue Tracker
By Design
Votes
1
Found in
2021.2
2021.2.0f1
2022.1
Issue ID
1378385
Regression
No
Can't create a new button for each element of the list when using ScriptableObject script
Reproduction steps:
1. Open the user's attached project
2. Select Assets > Plugins > Scripts > "Skills" ScriptableObject
3. Open the "Relies On Skills" list and add new items
Expected result: List full of buttons
Actual result: One Button in the list
Reproduced in: 2021.2.5f1, 2022.1.0b1
Could not test with: 2019.4.33f1, 2020.3.23f1 (error about an inability to change string to char)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Enum fields are rendered as Integer fields when serialized in a nested structure
- Sprites in a UIDocument expand when hovered over and the sprite is in a Sprite Atlas
- The Property's reference does not default to "_MainTex" when creating a new Texture2D Property in a ShaderGraph
- The "--additional-libraries" argument is ignored when building projects with the IL2CPP scripting backend
- Matching Selectors list not updating correctly with element's pseudo-state updates
Resolution Note:
Since PropertyDrawers are shared between all instances, CreatePropertyGUI() needs to always returns a new VisualElement. Here is a modified version of the custom property drawer that will allow you to edit each value independently.
[CustomPropertyDrawer(typeof(SkillHolderSerialized), true)]
public class SkillHolderSerializedDrawer : PropertyDrawer
{
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
var container = new VisualElement();
CreateSkillEditor(container, "skill.");
return container;
}
public static void CreateSkillEditor(VisualElement container, string bindingPathPrefix)
{
var uuid = new IntegerField()
{
label = "Uuid",
bindingPath = $"{bindingPathPrefix}{nameof(Skill.uuid)}"
};
container.Add(uuid);
var nameField = new TextField()
{
label = "Skill Name",
bindingPath =$"{bindingPathPrefix}{nameof(Skill.skillName)}"
};
container.Add(nameField);
var descriptionField = new TextField()
{
label = "Skill Description",
bindingPath = $"{bindingPathPrefix}{nameof(Skill.skillDescription)}",
multiline = true
};
container.Add(descriptionField);
}
}