Get the height of PropertyField of UnityEvent

[Serializable]
public class FooEvent : UnityEvent<string>
{
}
[Serializable]
public class Foo
{
    public string Name;
    public FooEvent FE;
}

I am writing PropertyDrawer for Foo. Normally, GetPropertyHeight can be calculate EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing but the height of FooEvent should be dynamic. How do I calculate the height?

For anyone finding this (and for my own future reference because this is the second time I had to implement it and probably won’t be the last):

height += EditorGUIUtility.singleLineHeight * 3.5f;
int listSize = property.FindPropertyRelative("Foo")
                    .FindPropertyRelative("m_PersistentCalls.m_Calls").arraySize;
height += Mathf.Max(1, listSize) * EditorGUIUtility.singleLineHeight * 2.61f;

.FindPropertyRelative("m_PersistentCalls.m_Calls")
I had to dig pretty deep into Unity code to get that one. Don’t ask me what it means, because I’ve forgotten.

Magic numbers:
3.5f - Initial size of the property block with 0 or 1 items.
2.61f - seems to be the best multiplier for dynamic growth. Any smaller and the +/- buttons get covered. Any bigger and you get empty space. (results may vary depending on monitor/resolution??)

2 Likes

thank you so so much for this

Doesn’t this work?

EditorGUI.GetPropertyHeight(property.FindPropertyRelative("FE"), true)
1 Like

Awesome!!!