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!

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.

OK not my solution but get the package attached to this:

link text

you should be able to see how GameObjects are set for EditorWindows.

  1. Code would be nice.

  2. You should get the GameObject through the FindObject(s)OfType method or any other Find method.