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
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");
}
}