Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


RectTransform

Position, size, anchor and pivot information for a rectangle.
Read time 13 minutesLast updated 4 days ago

Definition

public sealed class RectTransform : Transform, IEnumerable

Remarks

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

Property

Description

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.
sendChildDimensionsChangeWhether the RectTransform notifies components when a child RectTransform changes dimensions.
sizeDeltaThe size of this RectTransform relative to the distances between the anchors.

Methods

Method

Description

ContainsChecks whether the world-space bounding box of this RectTransform fully contains the world-space bounding box of another RectTransform.
FitInsideCoplanarRectTransformMoves and optionally shrinks this RectTransform so that it fits inside the given coplanar RectTransform.
ForceUpdateRectTransformsForces immediate processing of any pending
Transform
-change notifications.
GetLocalBottomReturns the y coordinate of the bottom edge of this RectTransform in its parent's coordinate space.
GetLocalCornersGet the corners of the calculated rectangle in the local space of its Transform.
GetLocalLeftReturns the x coordinate of the left edge of this RectTransform in its parent's coordinate space.
GetLocalRightReturns the x coordinate of the right edge of this RectTransform in its parent's coordinate space.
GetLocalTopReturns the y coordinate of the top edge of this RectTransform in its parent's coordinate space.
GetWorldCornersGet the corners of the calculated rectangle in world space.
GetWorldRectReturns the world-space axis-aligned bounding box of this RectTransform.
IsCoplanarWithDetermines whether this RectTransform is coplanar with the given RectTransform.
SetAnchorsSets both anchorMin and anchorMax to the same value, collapsing the anchor to a point.
SetInsetAndSizeFromParentEdgeSet the distance of this rectangle relative to a specified edge of the parent rectangle, while also setting its size.
SetLocalBottomMoves the bottom edge of this RectTransform to the specified position in its parent's coordinate space.
SetLocalLeftMoves the left edge of this RectTransform to the specified position in its parent's coordinate space.
SetLocalRightMoves the right edge of this RectTransform to the specified position in its parent's coordinate space.
SetLocalTopMoves the top edge of this RectTransform to the specified position in its parent's coordinate space.
SetPivotAndAnchorsSets the pivot, anchorMin, and anchorMax to the same value.
SetPivotWithCounterAdjustSets the pivot point of the
RectTransform
, adjusting the position to keep the rectangle in place.
SetSizeWithCurrentAnchorsSets the
RectTransform
calculated rect to a given size on the specified axis.
TryFitInsideCoplanarRectTransformChecks that this RectTransform is coplanar with the given RectTransform, then moves and optionally shrinks it to fit inside.

Static Events

Member

Description

reapplyDrivenPropertiesEvent invoked when a
RectTransform
needs its driven properties reapplied.

Enums

Enum

Description

RectTransform.AxisEnum to specify an axis, which can be either horizontal or vertical.
RectTransform.EdgeEnum used to specify one edge of a rectangle.
RectTransform.FitResultIndicates the result of a RectTransform fit operation.

Delegates

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.