- Home /
Getting the topmost parent
Suppose you have a runtme generated gameobject hierarchy like this (names not actually similar):
GameObject Another Object And Another ... And yet another object Object that is the child of a child (etc)
If you are the "object that is the child of a child (etc)" how do you get your topmost parent?
Answer by Bunny83 · Dec 26, 2011 at 11:15 PM
It's a mystery how you have missed that. However just in case you really haven't found it (neither in the documentation nor via google): Transform.root.
well, this sure beats using a series of recursive name checking!
Ironically this is now the top result on google when you search for "Unity root gameobject" or "Unity top most parent".
and even more ironically, the link in the answer throws a 404 error
more ironically is that Unity keeps changing its documentation links, inserts automatic redirects which point to the wrong file. The redirect is almost correct but it pointed to
https://docs.unity3d.com/ScriptReference/Transform-root.htm
ins$$anonymous$$d of
https://docs.unity3d.com/ScriptReference/Transform-root.html
So they forgot the "l" at the end. Anways, i've fixed the link.