Home > other >  ArgumentException: Getting control 1's position in a group with only 1 controls when doing repa
ArgumentException: Getting control 1's position in a group with only 1 controls when doing repa

Time:09-27

Problem:-

[CustomPropertyDrawer (typeof (GameObject))]  
public class GameObjectDrawer : PropertyDrawer
{

    Editor gameObjectEditor;
    GameObject _gameObject;
    
    public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
    {
      GUILayout.Button ("Hello");
    }
}

Here is the code I don't know why I'm getting this error

Error

CodePudding user response:

Within a property drawer you can not use the auto-layout calls from GUILayout or EditorGUILayout.

You rather need to use the GUI or EditorGUI and specifically pass in the exact Rect of where and how big to draw according field.

so in your case e.g.

[CustomPropertyDrawer (typeof (GameObject))]  
public class GameObjectDrawer : PropertyDrawer
{
    public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
    {
        GUI.Button(position, "Hello");
    }
}
  • Related