Repository navigation
Sizing a RectTransform
Four step types move or resize a UI element. Pick the one that matches how you're thinking about it:
| Type | Think of it as | Reach for it when |
|---|---|---|
Anchored Position |
Where it sits. Size stays the same. | Sliding something in or out |
Size Delta |
How big it is, growing out from its pivot | A panel that expands, a bar that grows |
Offset Min |
Where its left and bottom edges are | Pulling one side in or out |
Offset Max |
Where its right and top edges are | Pulling one side in or out |
All four take X and Y (Z is ignored) and support Snapping.
In every one of these steps, a positive number means right (for X) or up (for Y).
That matches the Inspector's Left and Bottom fields, but not Right and Top. Unity shows those two with the sign flipped, so that a positive number there always means "pushed inwards".
So a panel inset 12 pixels on every side reads Left 12, Bottom 12, Right 12, Top 12 in the Inspector, but in a step it's:
Offset Min (12, 12)Offset Max (-12, -12)
Tip
Copying a Right or Top value from the Inspector into a step? Flip its sign.
Anchored Position and Size Delta move the whole box. Offset Min and Offset Max move one corner and hold the other still. So modify either AnchorPos/SizeDelta or OffsetMin/Max unless you want to see them undo each other every frame.
For example: slide a panel 100 pixels right with Anchored Position, while an Offset Min step holds its left edge. The slide moves both edges, the Offset Min step drags the left edge back, and the panel ends up stretching to the right instead of moving.
Two from the same group are fine together: sliding while growing, or moving both corners.
If the element's anchors are spread apart (it stretches with its parent), Size Delta isn't a size in pixels. It's how much bigger than the anchored area the element is:
-
(0, 0)exactly fills it. -
(-24, -24)is 12 pixels smaller all round.
If you want a literal pixel size, un-stretch the anchors first.
Under the hood
- A RectTransform really stores
anchoredPositionandsizeDelta(plus anchors and pivot).offsetMinandoffsetMaxare worked out from those. SettingoffsetMinchanges bothsizeDeltaandanchoredPositionso thatoffsetMaxstays where it was, and the other way round. That's why the two groups fight and the members of one group don't. - Measured on a 100×40 rect: setting
offsetMinfrom(-50, -20)to(-10, -10)also movedsizeDeltato(60, 30)andanchoredPositionto(20, 5). - The Inspector's Right and Top fields are
-offsetMax.xand-offsetMax.y.
Installation
Code API
Basic usage
Advanced usage
- Punch and Shake
- Sizing a RectTransform
- Movement Paths
- Sound
- Custom Property
- Material and Shader Properties
- Stylised Motion
- Interrupting and Chaining
- Mirroring
- Copy and Paste
- Animation Sets
- Scene Gizmos
Nitty-gritties
Warnings and Troubleshooting