- Home /
Accessing a GameObject from an EditorWindow
Hi guys,
I'm creating an EditorWindow for my project and I have to access a GameObject in the Hierarchy. But the EditorWindow doesn't have any transform or gameObject variable, so I can't find any way to do that. Please help.
Thanks in advance!
Answer by RudyTheDev · Dec 07, 2014 at 10:00 PM
EditorWindow is not linked to any objects. But you can use pretty much what you would normally use to find game objects without having prior references to them (like, from any generic class).
GameObject.Find("Your Game object"); or maybe Selection.gameObjects. You can ask user to manually drag&drop it onto a EditorGUILayout.ObjectField.
Answer by Mmmpies · Dec 07, 2014 at 10:13 PM
OK not my solution but get the package attached to this:
you should be able to see how GameObjects are set for EditorWindows.
Answer by static_cast · Dec 07, 2014 at 10:02 PM
1) Code would be nice.
2) You should get the GameObject through the FindObject(s)OfType method or any other Find method.
Your answer
Follow this Question
Related Questions
How to hide every game object as per Hierarchy in active scene? 1 Answer
Access a child from the parent or other gameObject. 2 Answers
EditorWindow that changes properties of a custom gameObject 0 Answers
How to add an asset to a script-enabled public game object? 1 Answer
Deleting GameObjects 1 Answer