Search code examples
c#unity-game-enginetransformparent-childgameobject

Why does Unity use transform instead of gameObject with some functions such as GetChild()?


Unity uses transform.GetChild(childNum) as opposed to gameObject.GetChild(childNum).

I understand that every GameObject in Unity has a Transform component and the function returns the Transform of the child, but wouldn't it be more logical to use the GameObject class to get a child as it refers to the actual GameObject in the scene or project and not just a component? Why is the Transform used for finding hierarchical information?


Solution

  • Why is the Transform used for finding hierarchical information?

    Because the transforms serve as (and are) the anchors between children and parent, both figuratively and literally.