EditorGUILayout.Foldout not working properly - results in argument exceptions

:

For starters, I have successfully created a CustomPropertyDrawer that presents an also functioning custom property type.

:

The problem occurs when I try to create a Foldout that contains everything that that CustomPropertyDrawer does within OnGUI.

:

I followed the information on these links:

  1. EditorGUILayout.Foldout documentation
  2. A related Unity Answer that backs up the documentation

:

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
        showMatrix = EditorGUILayout.Foldout(showMatrix, "Matrix");

        if (showMatrix)
        {
            // custom property code
        }
}

:

Above is exactly what my code looks like (I even tried commenting out the “custom property code” that you see in the code snippet above, to no avail).

:

So, my question is, why is this not working? Is it a bug? Or is this outdated and I need to find a new solution?

Propertydrawers can’t use GUILayout or EditorGUILayout stuff. A PropertyDrawer gets a rect that it has to use. Everything you draw has to fit into the “position” rect. If you need more space for your property you have to override the GetPropertyHeight method and return the required height.

Again you can’t use any layout functions since the default inspector doesn’t even propergate the layout event to property drawers.