Version: 2023.1
LanguageEnglish
  • C#

RectTransform

class in UnityEngine

/

Inherits from:Transform

/

Implemented in:UnityEngine.CoreModule

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

Position, size, anchor and pivot information for a rectangle.

RectTransforms are used for GUI but can also be used for other things. It's used to store and manipulate the position, size, and anchoring of a rectangle and supports various forms of scaling based on a parent RectTransform.

Note: The Inspector changes which properties are exposed based on which anchor preset is in use. For more information see Rect Transform and Basic Layout.

Properties

anchoredPositionThe position of the pivot of this RectTransform relative to the anchor reference point.
anchoredPosition3DThe 3D position of the pivot of this RectTransform relative to the anchor reference point.
anchorMaxThe normalized position in the parent RectTransform that the upper right corner is anchored to.
anchorMinThe normalized position in the parent RectTransform that the lower left corner is anchored to.
drivenByObjectThe object that is driving the values of this RectTransform. Value is null if not driven.
offsetMaxThe offset of the upper right corner of the rectangle relative to the upper right anchor.
offsetMinThe offset of the lower left corner of the rectangle relative to the lower left anchor.
pivotThe normalized position in this RectTransform that it rotates around.
rectThe calculated rectangle in the local space of the Transform.
sizeDeltaThe size of this RectTransform relative to the distances between the anchors.

Public Methods

ForceUpdateRectTransformsForce the recalculation of RectTransforms internal data.
GetLocalCornersGet the corners of the calculated rectangle in the local space of its Transform.
GetWorldCornersGet the corners of the calculated rectangle in world space.
SetInsetAndSizeFromParentEdgeSet the distance of this rectangle relative to a specified edge of the parent rectangle, while also setting its size.
SetSizeWithCurrentAnchorsMakes the RectTransform calculated rect be a given size on the specified axis.

Events

reapplyDrivenPropertiesEvent that is invoked for RectTransforms that need to have their driven properties reapplied.

Delegates

ReapplyDrivenPropertiesDelegate used for the reapplyDrivenProperties event.

Inherited Members

Properties

gameObjectThe game object this component is attached to. A component is always attached to a game object.
tagThe tag of this game object.
transformThe Transform attached to this GameObject.
hideFlagsShould the object be hidden, saved with the Scene or modifiable by the user?
nameThe name of the object.
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).

Public Methods

BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentGets a reference to a component of type T on the same GameObject as the component specified.
GetComponentInChildrenGets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject.
GetComponentInParentGets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the same GameObject as the component specified.
GetComponentsInChildrenGets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject.
SendMessageCalls the method named methodName on every MonoBehaviour in this game object.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
TryGetComponentGets the component of the specified type, if it exists.
GetInstanceIDGets the instance ID of the object.
ToStringReturns the name of the object.
DetachChildrenUnparents all children.
FindFinds a child by name n and returns it.
GetChildReturns a transform child by index.
GetLocalPositionAndRotationGets the position and rotation of the Transform component in local space (that is, relative to its parent transform).
GetPositionAndRotationGets the position and rotation of the Transform component in world space.
GetSiblingIndexGets the sibling index.
InverseTransformDirectionTransforms a direction from world space to local space. The opposite of Transform.TransformDirection.
InverseTransformDirectionsTransforms multiple directions from world space to local space overwriting each original position with the transformed version. The opposite of Transform.TransformDirections.
InverseTransformPointTransforms position from world space to local space.
InverseTransformPointsTransforms multiple positions from world space to local space overwriting each original position with the transformed version.
InverseTransformVectorTransforms a vector from world space to local space. The opposite of Transform.TransformVector.
InverseTransformVectorsTransforms multiple vectors from world space to local space overwriting each original position with the transformed version. The opposite of Transform.TransformVectors.
IsChildOfIs this transform a child of parent?
LookAtRotates the transform so the forward vector points at /target/'s current position.
RotateUse Transform.Rotate to rotate GameObjects in a variety of ways. The rotation is often provided as an Euler angle and not a Quaternion.
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 from local space to world space.
TransformDirectionsTransforms multiple directions from local space to world space overwriting each original direction with the transformed version.
TransformPointTransforms position from local space to world space.
TransformPointsTransforms multiple points from local space to world space overwriting each original point with the transformed version.
TransformVectorTransforms vector from local space to world space.
TransformVectorsTransforms multiple vectors from local space to world space overwriting each original vector with the transformed version.
TranslateMoves the transform in the direction and distance of translation.

Static Methods

DestroyRemoves a GameObject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadDo not destroy the target Object when loading a new Scene.
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
InstantiateClones the object original and returns the clone.

Operators

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.