- Home /
PropertyDrawer with a Generic List Property?
I've been working on a PropertyDrawer for my Attribute class:
[System.Serializable]
public class Attribute : IGUIItemInfo
{
public EAttributeName attributeName;
public float max;
public float current;
public float baseValue;
public List<Modifier> mods;
My issue is with the mods property. With the default inspector I can see the mods just fine. When I try to add them to my custom PropertyDrawer, I just see a fold icon and no contents:
EditorGUI.PropertyField (r, property.FindPropertyRelative ("mods"), GUIContent.none);
The default shows up as follows:
The custom one shows this:
How would I code for the mods to show up like the first example?
I'm looking for a way to make property drawers for a List too. No luck so far!
Answer by Tortuap · Nov 02, 2015 at 09:40 PM
Simply don't forget to set the latest parameter of method EditorGUI.PropertyField :
EditorGUI.PropertyField ( ..., includeChildren:true );
Answer by BlinksTale · Aug 08, 2014 at 04:31 PM
The default one uses an array, not a list. That's why it has a set size which you must define at the start. Lists are dynamic, they can change sizes easily, but regular arrays are not.
You can change this by switching this:
public List<Modifier> mods;
to this:
public Modifier[] mods;
If you aren't familiar with arrays, be sure to read up on them.
http://docs.unity3d.com/ScriptReference/Array.html
http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx
Although I would guess more of the problem is in understanding what makes properties appear that way in the editor, not how arrays work. :)
Actually from a serialized data point of view there's not difference between arrays and Lists inside the editor. Arrays and generic Lists are displayed exactly the same way. The problem here is that a list / array doesn't show up as a single serialized property. The property actually has child properties.
Some useful things in the SerializedProperty in relation to lists arrays are:
Next note the bool parameter
Your answer
![](https://koobas.hobune.stream/wayback/20220613095510im_/https://answers.unity.com/themes/thub/images/avi.jpg)