Hey everyone, I have been looking for a way to find the root gameobject of a prefab at run-time but I am have trouble finding a good solution. For example a scene hierarchy will be: Object1 Object2 Prefab Instance Child1 Child2 Child3 I have no way of telling which layer of the prefab I will be selecting OnClick as it is an environment prefab. So i could be colliding with Child1, Child 3 or any other level depending how deep it goes. The problem is I need to know what the 'root' game object of the prefab (In this case it'll be Prefab Instance) is because it has a script attached to it which will give me information on the current selected prefab. Is there any way of finding this out through unity's API or do I have to do a custom script? So far transform.root doesn't work for this case and PrefabUtility is an editor script so guessing that wont work either.
If you already have a script on that prefab root, then from anywhere in the Childs (or even the PrefabInstance itself), you can use .GetComponentInParent<MyInterestingScript>() to find it "above you." https://docs.unity3d.com/ScriptReference/Component.GetComponentInParent.html