How to update a content size fitter during runtime.

Hello everyone,

I have the following setup:

Button (With Horizontal Layout Group and Content Size Fitter components)

  • Text (With Content Size Fitter component)

I can enter a text into the text component and the button resizes to fit it, shrinking and growing as needed.

However, if I change the text at runtime (using: .GetComponent().text) the button does not resize. Can anyone tell me how I can get the button to update its size during runtime?

For @joshskelton (and others who might stumble across this post):

I solved the problem with the following setup:

  • Button (with Horizontal Layout Group; Control Child Width, Height; Child force expand Width and Content Size Fitter (Horizontal Unconstrained, Vertical Preferred))
  • Text (Horizontal Overflow Wrap, Vertical Overflow Truncate)

I saw the warning @oscarlundberg mentioned, but since it worked in the editor, I was left under the impression that it was just not good style.

I’d like to know too.