Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Transform

Position, rotation and scale of an object.
Read time 9 minutesLast updated 2 days ago

Definition

public class Transform : Component, IEnumerable

Remarks

Every object in a Scene has a Transform. It's used to store and manipulate the position, rotation and scale of the object. Every Transform can have a parent, which allows you to apply position, rotation and scale hierarchically. This is the hierarchy seen in the Hierarchy pane. They also support enumerators so you can loop through children using:
using UnityEngine;public class Example : MonoBehaviour{ // Moves all transform children 10 units upwards! void Start() { foreach (Transform child in transform) { child.position += Vector3.up * 10.0f; } }}
Additional Resources: The component reference, Physics class.

Properties

Property

Description

childCountThe number of children the parent Transform has.
eulerAnglesThe rotation as Euler angles in degrees.
forwardReturns a normalized vector representing the blue axis of the transform in world space.
hasChangedHas the transform changed since the last time the flag was set to 'false'?
hierarchyCapacityThe transform capacity of the transform's hierarchy data structure.
hierarchyCountThe number of transforms in the transform's hierarchy data structure.
localEulerAnglesThe rotation as Euler angles in degrees relative to the parent transform's rotation.
localPositionPosition of the transform relative to the parent transform.
localRotationThe rotation of the transform relative to the transform rotation of the parent.
localScaleThe scale of the transform relative to the GameObjects parent.
localToWorldMatrixMatrix that transforms a point from local space into world space (Read Only).
lossyScaleThe global scale of the object (Read Only).
parentThe parent of the transform.
positionThe world space position of the Transform.
rightThe red axis of the transform in world space.
rootReturns the topmost transform in the hierarchy.
rotationA Quaternion that stores the rotation of the Transform in world space.
upThe green axis of the transform in world space.
worldToLocalMatrixMatrix that transforms a point from world space into local space (Read Only).

Methods

Method

Description

DetachChildrenUnparents all of the target object's children.
FindFinds a child by name
n
and returns it.
GetChildReturns a transform child by index.
GetLocalPositionAndRotationUpdates the value of the out parameters
localPosition
and
localRotation
with the transform's current
position
and
rotation
in local space (that is, relative to its parent's
transform
).
GetPositionAndRotationUpdates the value of the out parameters
position
and
rotation
with the transform's current
position
and
rotation
in world space (that is, relative to the scene's origin coordinates).
GetSiblingIndexGets the index of this Transform, relative to its siblings.
InverseTransformDirectionTransforms the direction
x
,
y
,
z
from world space to local space. The opposite of Transform.TransformDirection.
InverseTransformDirectionsTransforms multiple directions from world space to local space writing the transformed positions to a possibly different location. The opposite of Transform.TransformDirections.
InverseTransformPointTransforms the position
x
,
y
,
z
from world space to local space.
InverseTransformPointsTransforms multiple positions from world space to local space writing the transformed positions to a possibly different location.
InverseTransformVectorTransforms the vector
x
,
y
,
z
from world space to local space. The opposite of Transform.TransformVector.
InverseTransformVectorsTransforms the vector
x
,
y
,
z
from world space to local space writing the transformed positions to a possibly different location. The opposite of Transform.TransformVector.
IsChildOfIs this transform a child of parent?
LookAtRotates the transform so the forward vector points at target's current position.
RotateThe implementation of this method applies a rotation of
zAngle
degrees around the z axis,
xAngle
degrees around the x axis, and
yAngle
degrees around the y axis (in that order).
RotateAroundRotates the transform about
axis
passing through
point
in world coordinates by
angle
degrees.
SetAsFirstSiblingMove the transform to the start of the local transform list.
SetAsLastSiblingMove the transform to the end of the local transform list.
SetLocalPositionAndRotationSets the position and rotation of the Transform component in local space (i.e. relative to its parent transform).
SetParentSet the parent of the transform.
SetPositionAndRotationSets the world space position and rotation of the Transform component.
SetSiblingIndexSets the sibling index.
TransformDirectionTransforms direction
x
,
y
,
z
from local space to world space.
TransformDirectionsTransforms multiple directions from local space to world space writing the transformed directions to a possibly different location.
TransformPointTransforms the position
x
,
y
,
z
from local space to world space.
TransformPointsTransforms multiple points from local space to world space writing the transformed points to a possibly different location.
TransformVectorTransforms vector
x
,
y
,
z
from local space to world space.
TransformVectorsTransforms multiple vectors from local space to world space writing the transformed versions to a possibly different location.
TranslateMoves the transform by x along the x axis, y along the y axis, and z along the z axis.

Inheritance

Inherited Members

Operators

Operator

Description

operator ==Compares two object references to see if they refer to the same object.
boolDetermines whether the object exists.
operator !=Compares if two objects refer to a different object.