I have a Button element with a Content Size Fitter set to preferred size. The goal is to make the Button’s RectTransform resize automatically based on its text. However, I noticed that the rect doesn’t automatically resize when new text is pushed to its child’s Text component. It only resizes when the child’s values change (e.g. if I manually change the font size) or when the button is selected.
Is there any way to manually force Unity to “update” the button as soon as the text changes? I know about Button.Select()
, but I have two buttons visible at the same time, and I want all of this to happen in one frame.
Here’s an example of what the buttons look like when they’re first set to active and populated with text:
And here’s what they look like after the bottom one is highlighted: