ContentSizeFitter
Resizes a node to what is actually inside it, such as a dialogue box grown as tall as its own text, instead of a fixed size that needs re-authoring in every language. Its anchor picks which point stays put as it grows. Goes under a Canvas.
On this page
Add it
Add component → ContentSizeFitter in the Inspector, on the node that should carry it.
From a script
A script on the same node writes these fields by name. ContentSizeFitter is the name to pass.
rgs
set_number("ContentSizeFitter", "padding", 8.0);
set_point("ContentSizeFitter", "min", vec2(0.0, 0.0));
set_point("ContentSizeFitter", "max", vec2(0.0, 0.0));
set_point("ContentSizeFitter", "anchor", vec2(0.5, 0.5)); Fields
| Field | Script name | Kind | Default | What it does |
|---|---|---|---|---|
| Horizontal | horizontal | one of Unconstrained, Preferred | Unconstrained | Whether the width follows the content. |
| Vertical | vertical | one of Unconstrained, Preferred | Preferred | Whether the height follows the content. |
| Padding | padding | number, at least 0 | 8 | Space left around the content on every side, in UI units; the Text on the node is laid out inside it. |
| Min | min | two numbers (x, y), at least 0 | (0, 0) | Smallest the box may get, in UI units. |
| Max | max | two numbers (x, y), at least 0 | (0, 0) | Largest the box may get, in UI units. Zero on an axis means no limit. |
| Anchor | anchor | two numbers (x, y), 0 to 1, step 0.01 | (0.5, 0.5) | The point of the original box that stays put as it resizes, (0,0) top-left to (1,1) bottom-right. |