PropertyDrawer for a property is not executed when property is an array?


Edit: SOLUTION
-----------------------
I have found the solution, and it was actually very simple. EditorGUI.PropertyField(instanceOfNextQuest) have an overload which takes a bool as input. This bool defines whether the PropertyField is suppose to draw any child properties. In order to draw an array using EditorGUI.PropertyField() this bool must be set to TRUE

EditorGUI.PropertyField(someProperty, true, null)


PROBLEM
-----------------------

Hi there uniteers.
In my current editor script, I have a class called NextQuest which is drawn through the use of EditorGUI.PropertyField(instanceOfNextQuest).

[System.Serializable]
public class NextQuest : System.Object
{
   // Some logic
}

NextQuest have its own proprety drawer:

[CustomPropertyDrawer(typeof(NextQuest))]
public class NextQuestDrawer : PropertyDrawer
{

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // Some logic
    }
}

The OnGUI is being executed when NextQuest is being declared as an ordinary variable. The OnGUI is NOT executed when NextQuest is declared as an array of NextQuests.

public class QuestClass : ScriptableObject
{
   NextQuest nextQuest; // OnGUI is called
   NextQuest[] nextQuestArr; // OnGUI is NOT called
}

What am I missing here? I am pretty sure this worked earlier. We just upgraded to 4.5.3.f1, but I can’t find any notes or comments about bugged PropertyDrawers for arrays.

1 Like

Oh well, I am beginning to think its a bug now. I just noticed one of my previous PropertyDrawers which made use of an array doesn’t work anymor. I know this worked earlier, because I had used it on multiple occuations.

I would appreciate if someone out there could either confirm or disprove this.

Okay, either I am doing something wrong here, or there is a somewhat weird bug going on. It appears that EditorGUI.PropertyField() can’t draw any arrays properly anymore. It doesn’t work with int, enums, strings or anything. I have attached an example. List of ints is a List, while Ordinary int is just an int. They are both drawn using the EditorGUI.propertyfield().

Property drawers are limited to very simple cases. As soon as it gets a little more complex like with arrays or lists, they aren’t well suited anymore. At least that was my experience which seems to be close to yours, unfortunately.

You are properly right, but I am no longer talking about custom property drawers. Unity is having problems drawing simple array properties such as arrays of ints, string and enums, without the use of custom drawers.

I always had to use custom drawers for arrays, not just for the elements, because it simply didn’t work otherwise.

Even for standard types? For a long time I haven’t had to use any property drawers, even custom classes. This is the first time I encounter this. I am currently downloading 4.5.1 to see whether its a version bug.

In simple cases, I am just using:

This draws the array in the usual way.

I just downgraded to 4.5.1. Problem stil occuring…

I am still wresting with this issue. Anyone have any clues or ideas of this behavior? I am trying now to go even further back to 4.3.2, but I am not sure whether it will work. I can’t figure out whether it is an unity bug or simply just something stupido from my site.

Okay, this was a bit akward. I have found the solution, and it was actually very simple. EditorGUI.PropertyField(instanceOfNextQuest) have an overload which takes a bool as input. This bool defines whether the PropertyField is suppose to draw any child properties. In order to draw an array using EditorGUI.PropertyField() this bool must be set to TRUE
EditorGUI.PropertyField(someProperty, true, null)

2 Likes