How to fix ArgumentException?

Hi,

I’m getting this error:

UnityEngine.GUILayoutUtility.BeginLayoutGroup (UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options, System.Type LayoutType) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUILayoutUtility.cs:210)
UnityEditor.EditorGUILayout.BeginHorizontal (UnityEngine.GUIContent content, UnityEngine.GUIStyle style, UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:5847)

UnityEditor.EditorGUILayout.BeginHorizontal (UnityEngine.GUILayoutOption[] options) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/EditorGUI.cs:5826)
UnityEditor.InspectorWindow.AddComponentButton (UnityEditor.Editor[] editors) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:1208)
UnityEditor.InspectorWindow.OnGUI () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Inspector/InspectorWindow.cs:359)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

While using this code:

[CustomPropertyDrawer(typeof(Test))]
class TestDrawer : PropertyDrawer
{
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        if (Event.current.type == EventType.Repaint || Event.current.type == EventType.Layout)
        {
            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
            base.OnGUI(position, property, label);
        }
     }
}

And it doesn’t draw out properly, it just glitches the whole inspector.

I tried switching out the GUILayout.Box for GUI.skin.box.draw and got it to work, but it didn’t maintain the layout like I intend it to do.

I’ve been stuck on this for a couple hours, attempting to Google/search the Forum/Answers for a fix, but I couldn’t find one. All the answers that I found didn’t work for me.

Does anyone know of a fix for this? If so, how do I fix it?

Thank you,

KaliTech.

EDIT: I found a temporary fix(which I dislike, so I still need help) by increasing the position manually. It’s unreliable for my situation, but it works for now I guess.

Thanks.

EDIT: Here’s what I’m left with after Bunny83’s suggestion:

And with this code:

[CustomPropertyDrawer(typeof(Test))]
    class TestDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
            EditorGUILayout.Space();
            base.OnGUI(position, property, label);
        }
    }

Is there any good reason why you filter all events but repaint and layout? This will most likely cause tons of problems as every event is paired with a layout event. Since you let the layout events through but are blocking all others (except repaint) Unity might have trouble when iterating through it’s internal list of controls.

Also if you want more space for your property, you should override PropertyDrawer.GetPropertyHeight as well.

If you just want a space in the layouting system you should use GUILayout.Space which is ment for that purpose.

So in general you should be careful when filtering events. In your case you blocked all keyboard and mouse events. If you want to prevent interaction, just set GUI.enabled to false.

I found a solution(thanks for trying, Bunny83):

float extraSpace = 5;
Rect newPropertyRect = new Rect(position.x, position.y + extraSpace, position.width, position.height);
EditorGUI.PropertyField(newPropertyRect, property, label);

I had the same ArgumentException problem and it turns out the documentation for PropertyDrawer says:

Note that for performance reasons, EditorGUILayout functions are not usable with PropertyDrawers.

It used to work for me back on 2018, but it seems that Unity’s changed something on 2019 and using EditorGUILayout always causes this ArgumentException.

(Also, it looks like this warning was there even back on 5.6.)

That’s why Bunny’s solution helps.