Why do we access children through an object's transform?

I am reading about the various ways to access different game objects, specifically in my case, children. I have noticed that we are told to access children in a manner of ways through the Transform of said object. But I don’t seem to be able to find any place that explains why we would use the Transform to access children, when I thought that was just concerned with the scale, position and rotation. Admittedly, the Transform of a parent affects its children, but could someone explain or give me a link to a decent explanation on why it’s done this way? I want to understand it properly.

Thanks!

Hi,
This is an interesting question.
Unity uses the Scenegraph structure to organize a scene. Scenegraph defines a hierarchical structure of parents, children and siblings that are used for determining how objects should be placed, rotated and scale in relation to each other.

Scenegraph example

As you have probably noticed, the only property that all Gameobjects have in common is the Transform, since such determines its properties within the Scenegraph. Unity encapsulates everything about this Scenegraph in the Transform Class, which as I previously mentioned, is a mandatory element of a Gameobject.

Thus, because the Transform is the class that encapsulates the Scenegraph relative information of a particular Gameboject, and because the Gameobject is nothing more than a simple container (which can be decorated by means of attaching additional components or monobehaviours), you have to access the children of a gameobject through its transform property.

I hope that helped.

The main thing(*) childing does is to base position, rotation and scale on the parent’s. The child’s Transform is linked to the parent’s Transform.

So, if you think of it like “does this Transform have anything it’s tracking?” then it makes perfect sense that parents come from your Transform, to another Transform, and not from/to gameObjects.

(*)Can also use parenting as a way to make “folders,” like with an empty parent at 000, which you will never move. In that case, having a gameObject parent would make sense. But this is a lot rarer.