How do I find a gameObject's prefab parent?

Hello, I have a gameobject in my scene which is a deep child of an instantiated prefab. And I would like to know how to determine its prefab root/parent (in the scene) without having to resort to iterating up from parent to parent while comparing strings (which strikes me as very clumsy).

Obviously I cannot use transform.root since that would get me the topmost parent object, which could itself be a parent of my child object’s prefab, not the prefab itself.

Oh and that should be at runtime too, so I can’t use any editor function.

Since that sounds like a very simple thing I’m sure it’s possible but I haven’t found a way yet. Could anyone help please?

Perhaps you just need to add a component that stores that originating gameobject as a reference on its’ instantiation. If you happen to know ahead of time which gameobject child is in the parents hierarchy…

I know this answer isn’t directly related to the original question but I was trying figure out what the parent prefab was for a prefab variant in the editor itself and google took me here. Afterwards I figured it out so I thought I’d post my findings here just in case someone else does the same thing I did.


If you open the child prefab (As if you were going to edit the prefab) and then in the inspector, click the override dropdown in the top right. From there you should be able to see the parent prefab at the top as shown in the screenshot. If this isn’t showing up for you it’s possible that this was a feature added in a later version. I am running version 2020.3.25f1

191151-2022-01-13-16-23-26.png