- Home /
How to check if a component is on an instantiated prefab?
Hi all
I've been writing an inspector that has some buttons for aiding the artist in designing asset hierarchies:
I've accidentally discovered that these buttons can be pressed while the Inspector is displaying components of a prefab, which is undesirable.
I'm not sure if the solution is for the MonoBehaviour or the Editor script to prevent this input, but either way I need to be able to check if the component has been instantiated.
Is it possible to check if the current component is in the scene or project?
Thanks,
Ves
There's no way to check if an object has been instanciated with the Unity API, but you could add a flag to your object and set it to true when it's instantiated. If you add the ExecuteInEditmode atttribute to your script you can set the flaf to true in Awake. Then you only draw the buttons if that flag is true.
Answer by PouletFrit · Jun 02, 2014 at 05:43 PM
Use PrefabUtility.GetPrefabType it will return a PrefabType and with it you can check if its either a Prefab (project window) or a PrefabInstance (scene window)