Unity Transform

In by John FrenchPublished

The Transform component in Unity is used to manage the position, rotation, and scale of an object, and to manage its relationship with other objects.

Every Monobehaviour script can access its object’s transform component using the transform property (a shorthand reference to the current Transform).

Like this:

Transform myTransform = transform;

This allows any script to set the objects position, rotation, or scale, creating movement or changing an object’s size.

Because the Transform component holds orientation data, it’s also possible to get an object’s local directions using the transform reference, such as to get the forward direction of an object, for example.

Like this:

Vector3 forward = transform.forward;

Transform components are also used to manage the relationship between an object and other objects in the scene where, typically, a transform reference will be used to identify a parent object when an object is instantiated, for example.

Likewise, an object’s transform can be used to find the root in a hierarchy of objects by using the Root property.

Like this:

Transform rootTransform = transform.root;

See also: