Transform
Position, rotation and scale of an object.
Read time 9 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Inherits from: Component
- Implements: IEnumerable
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 |
|---|---|
| childCount | The number of children the parent Transform has. |
| eulerAngles | The rotation as Euler angles in degrees. |
| forward | Returns a normalized vector representing the blue axis of the transform in world space. |
| hasChanged | Has the transform changed since the last time the flag was set to 'false'? |
| hierarchyCapacity | The transform capacity of the transform's hierarchy data structure. |
| hierarchyCount | The number of transforms in the transform's hierarchy data structure. |
| localEulerAngles | The rotation as Euler angles in degrees relative to the parent transform's rotation. |
| localPosition | Position of the transform relative to the parent transform. |
| localRotation | The rotation of the transform relative to the transform rotation of the parent. |
| localScale | The scale of the transform relative to the GameObjects parent. |
| localToWorldMatrix | Matrix that transforms a point from local space into world space (Read Only). |
| lossyScale | The global scale of the object (Read Only). |
| parent | The parent of the transform. |
| position | The world space position of the Transform. |
| right | The red axis of the transform in world space. |
| root | Returns the topmost transform in the hierarchy. |
| rotation | A Quaternion that stores the rotation of the Transform in world space. |
| up | The green axis of the transform in world space. |
| worldToLocalMatrix | Matrix that transforms a point from world space into local space (Read Only). |
Methods
Method | Description |
|---|---|
| DetachChildren | Unparents all of the target object's children. |
| Find | Finds a child by name |
| GetChild | Returns a transform child by index. |
| GetLocalPositionAndRotation | Updates the value of the out parameters |
| GetPositionAndRotation | Updates the value of the out parameters |
| GetSiblingIndex | Gets the index of this Transform, relative to its siblings. |
| InverseTransformDirection | Transforms the direction |
| InverseTransformDirections | Transforms multiple directions from world space to local space writing the transformed positions to a possibly different location. The opposite of Transform.TransformDirections. |
| InverseTransformPoint | Transforms the position |
| InverseTransformPoints | Transforms multiple positions from world space to local space writing the transformed positions to a possibly different location. |
| InverseTransformVector | Transforms the vector |
| InverseTransformVectors | Transforms the vector |
| IsChildOf | Is this transform a child of parent? |
| LookAt | Rotates the transform so the forward vector points at target's current position. |
| Rotate | The implementation of this method applies a rotation of |
| RotateAround | Rotates the transform about |
| SetAsFirstSibling | Move the transform to the start of the local transform list. |
| SetAsLastSibling | Move the transform to the end of the local transform list. |
| SetLocalPositionAndRotation | Sets the position and rotation of the Transform component in local space (i.e. relative to its parent transform). |
| SetParent | Set the parent of the transform. |
| SetPositionAndRotation | Sets the world space position and rotation of the Transform component. |
| SetSiblingIndex | Sets the sibling index. |
| TransformDirection | Transforms direction |
| TransformDirections | Transforms multiple directions from local space to world space writing the transformed directions to a possibly different location. |
| TransformPoint | Transforms the position |
| TransformPoints | Transforms multiple points from local space to world space writing the transformed points to a possibly different location. |
| TransformVector | Transforms vector |
| TransformVectors | Transforms multiple vectors from local space to world space writing the transformed versions to a possibly different location. |
| Translate | Moves the transform by x along the x axis, y along the y axis, and z along the z axis. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |