CustomPropertyDrawer does not title List elements

Good morning fair programmers!

I’m building a PropertyDrawer for an object I would like to expose as a List<> in the inspector, I’m mostly there but I can’t find a way for the list to automatically add what’s generally Element 0, Element 1, … in fact that area comes out empty:

202640-filtercontroldrawer.jpg

and adding the label just shifts everything down:
202641-filtercontroldrawer2.jpg

I did try a few things such as adding a name member as other posts seem to suggest, but no victory over there.

Here’s the whole thing:

public class AmbiancePad : MonoBehaviour
{
    ...
    public List<SoundFilterControl> filters = new List<SoundFilterControl>();
    ...
}

[CustomPropertyDrawer(typeof(SoundFilterControl))]
class SoundFilterControlDrawer : PropertyDrawer
{
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        float margin = 12;
        int lines = 3;

        SerializedProperty controlMode = property.FindPropertyRelative("controlMode");
        if (controlMode.enumValueIndex == (int)SoundFilterControlMode.Distance)
        {
            lines += 4;
        }
        else
        {
            lines += 6;
        }

        SerializedProperty customCurveMode = property.FindPropertyRelative("curveMode");
        if (customCurveMode.enumValueIndex == (int) SoundFilterCurveMode.Custom)
        {
            lines += 1;
        }

        return EditorGUIUtility.singleLineHeight * lines + margin;
    }

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        SerializedProperty effect = AppendProperty(ref position, property, "filter");
        SerializedProperty controlMode = AppendProperty(ref position, property, "controlMode");

        if (controlMode.enumValueIndex == (int) SoundFilterControlMode.Distance)
        {
            AppendProperty(ref position, property, "distanceFrom");
            AppendProperty(ref position, property, "distanceMin");
            AppendProperty(ref position, property, "distanceMax");
        }
        else
        {
            AppendProperty(ref position, property, "controlParameters");
            AppendProperty(ref position, property, "controlParameter");
            AppendProperty(ref position, property, "effectParameter");
            AppendProperty(ref position, property, "effectControlRangeMin");
            AppendProperty(ref position, property, "effectControlRangeMax");
        }

        SerializedProperty curveMode = AppendProperty(ref position, property, "curveMode");
        if (curveMode.enumValueIndex == (int)SoundFilterCurveMode.Custom)
        {
            AppendProperty(ref position, property, "customCurve");
        }

        EditorGUI.EndProperty();
    }

    private SerializedProperty AppendProperty(ref Rect position, SerializedProperty property, string propertyRelativeName)
    {
        Rect propertyRect = EditorUtils.NextLineRect(ref position);
        SerializedProperty relativeProperty = property.FindPropertyRelative(propertyRelativeName);
        EditorGUI.PropertyField(propertyRect, relativeProperty);
        return relativeProperty;
    }
}

Thanks!

Ok found it, in fact, I needed to use the passed position and label to get what I wanted. I went too quickly over that at first. Here’s my solution to edit the “Element 0” label:

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
    EditorGUI.BeginProperty(position, label, property);
    Rect labelRect = new Rect(position.x, position.y, position.width, EditorUtils.LineHeight);
    EditorGUI.LabelField(labelRect, $"Filter Control {label.text[label.text.Length - 1]}");

The point of fiddling with label text is just to extract the “0” at the end of the default “Element 0” label string passed.