- Home /
How do I create a gameobject field in a custom editor?
Hello, I'm trying to add a gameobject field to a custom editor. I've tried with EditorGUILayout.ObjectField, but it doesn't work. Can you please help me?
I believe ObjectField
is the way to go.
Please, edit your question, provide the relevant code, and explain "what does not work".
Answer by ethanboompow · Jan 20, 2021 at 08:33 PM
@$$anonymous$$ I've been trying to figure this out too, and I finally feel I know how to go about this.
You can use EditorGUILayout.ObjectField(), but you must cast it into a game object.
For example,
exampleScript.exampleGO = (GameObject)EditorGUILayout.ObjectField("Example GO", exampleScript.exampleGO, typeOf(GameObject), true);
I hope this helps
Your answer
Follow this Question
Related Questions
Refreshing custom Inspector window while playing 1 Answer
Should I use Inspector or custom editor window? 1 Answer
SerializedObject.FindProperty returning null 2 Answers
Getting a target's gameobject in custom editor 1 Answer
Is there any way to hide the "Object picker" of an EditorGUILayout.ObjectField ? 2 Answers