- Home /
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?
You shouldn't add a Content Size Fitter component on an object whose parent has a Layout Group, because it should be driven by the layout group. You should get an error in the editor, that tells you this
Answer by arnad · Jun 09, 2017 at 09:03 PM
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.
If you think about it - You have the layout group telling the child to be a certain size, and the child wants to be a completely different size - So it can't work :)
Your answer
Follow this Question
Related Questions
How i colourize a Button and change the Font Size of it ? 1 Answer
Screen Sizes - HUD - Button Layout - Camera. 0 Answers
(C#) How to scale buttons and GUI Text to screen 1 Answer
Need more buttons to this script. 1 Answer
UI Button Sizing unit 0 Answers