Only first TextField can edit text

Hi there,
I’m currently dabbling with the CustomPropertyDrawer functionality and can’t figure out the following (minimized) problem:

Lets say I have a Scriptable Object with a custom (for convenience) inner class

[CreateAssetMenu(fileName = "Test", menuName = "ScriptableObjects/Test", order = 2)]
public class Test : ScriptableObject
{
    public InnerTest MyTest = new();

    [Serializable]
    public class InnerTest
    {
        public string a = "Hello";
        public string b = "World";
    }
}

I want to make the two strings a and b editable with a TextField, so I created a new drawer:

[CustomPropertyDrawer(typeof(Test.InnerTest))]
public class TestDrawer : PropertyDrawer
{
    public override void OnGUI(Rect Position, SerializedProperty InnerTestProp, GUIContent Label)
    {
        Rect Rect1 = new Rect(0, 0, 100, 20);
        Rect Rect2 = new Rect(0, 25, 100, 20);

        SerializedProperty AProp = InnerTestProp.FindPropertyRelative("a");
        SerializedProperty BProp = InnerTestProp.FindPropertyRelative("b");
        AProp.stringValue = EditorGUI.TextField(Rect1, AProp.stringValue);
        BProp.stringValue = EditorGUI.TextField(Rect2, BProp.stringValue);
    }
}

which looks decent

but for some reason I can only edit the first Textfield. Only "Hello" is selectable or changeable.

I guess I am missing some config somewhere, I’d be glad for a hint.
Thanks

Edit:

Funnily enough with EditorGUILayout.TextField its working, but I wanted to use the non-layout version to have manual placing :confused:

1 Answer

1

Hey, what you are missing is this method override:

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
    return 45;
}

Basically, you should return the height of your property here based on the amount of text fields you have, in your case it’s 45: 2 fields with height 20 + 5 for spacing between them