Skip to content

Components

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

FieldScript nameKindDefaultWhat it does
Horizontalhorizontalone of Unconstrained, PreferredUnconstrainedWhether the width follows the content.
Verticalverticalone of Unconstrained, PreferredPreferredWhether the height follows the content.
Paddingpaddingnumber, at least 08Space left around the content on every side, in UI units; the Text on the node is laid out inside it.
Minmintwo numbers (x, y), at least 0(0, 0)Smallest the box may get, in UI units.
Maxmaxtwo numbers (x, y), at least 0(0, 0)Largest the box may get, in UI units. Zero on an axis means no limit.
Anchoranchortwo 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.