- Home /
Get Monobehaviour play mode instance from editor instance
Hi,
I'm working on an editor window which has a reference to a MonoBehaviour in the scene. What I want is, when entering play mode, find the Monobehaviour which is the instance corresponding to the MonoBehaviour.
Is there any way to do that ?
== EDIT ==
Seems that what I want is not very clear so I'l try to explain better. I have a GameObject M in my scene with a Npc MonoBehaviour. I created an EditorWindow to edit the Npc, so in my editor I have a reference to the Npc component. The thing is when I enter play mode, Unity deletes the GameObject M and creates a clone M'. What I want is to know if there's a way to get to gameobject M' from my EditorWindow.
I can't understand correctly .. would you like that in your editor window you can choose a class and that objects of that class are highlighted in the hierarchy? Or that passing a prefab to the editor highlights the objects in the hierarchy that come from that prefab?
Please explain the situation better so we can help you.
Sorry I wasn't clear enough, i'll try to explain better. I have a GameObject M in my scene with a Npc MonoBehaviour. I created an EditorWindow to edit the Npc, so in my editor I have a reference to the Npc component. The thing is when I enter play mode, Unity deletes the GameObject M and creates a clone M'. What I want is to know if there's a way to get to gameobject M' from my EditorWindow.
Ok .. if I understand correctly, you need that, once you enter the execution mode, you have to retrieve the gameObject of class M .. right?
If so, just use the following code:
M myObjectClone = Object.FindObjectOfType <M> ();