- Home /
PropertyDrawer inside an array
Hi there,
I have a custom property drawer for an object A, that renders exactly as I want. Besides, I have another object B owning an array of A. In the inspector, the property drawer works as expected, but not the "array part" : the usual string "Element 0" that precedes the first object is not here anymore (idem for the following Elements 1, 2, etc.), and I can't collapse each element of the array anymore.
Is there something to do inside the PropertyDrawer (though I guess it's should not take care of the rendering of my object A when it's embedded in an array), or should I make a custom Editor for my object B, or something else?
Here is an image to illustrate:
Thanks in advance for your help!
Answer by CodesCove · May 25, 2021 at 02:46 PM
Custom Property Drawer is ok for this. You just need to iterate the array inside the drawer. Pseudocode:
SerializedProperty serialized_A_Array= property.FindPropertyRelative("A_Array");
foreach (SerializedProperty A in serialized_A_Array)
{
EditorGUI.PropertyField([GetPropertyHeight], A, ...)
if (A.isExpanded)
{
//Draw the A as you like. Override the GetPropertyHeight() to position the lines correctly
EditorGUI.PropertyField([GetPropertyHeight], A.FindPropertyRelative("Position");
// etc..
}
}
Hi, thanks for your answer! You suggest to iterate the array in the drawer, but for now I only have a drawer for A, which doesn't own the array. It's B that owns the array, and I don't have a drawer for B. You then suggest to create a property drawer for B as well?
Thank you again, I've figured out, as you mentioned in my property drawer, I had to use the EditorGUI.FouldOut() method, and then check if property.IsExpanded. Thanks!
Great you got it working! I convert my comment to answer.
Your answer
Follow this Question
Related Questions
SerializedProperty isn't being detected as an array? 1 Answer
How to prevent overlap when using nested arrays in CustomPropertyDrawers? 1 Answer
EditorGUI.IntField always 0 after GameStart 0 Answers
How do I property Drawer? 1 Answer
Custom Editor/Custom Property Drawer combo, breaks Enable button 1 Answer