I want some kind of auto size functionality for the UI.Text element. The ContentSizeFitter seems to do exactly what I am looking except that it won’t work if the Text itself is part of a hierarchy where a parent element already contains the ContentSizeFitter component.
The manual writes something about how to “Make children of a Layout Group fit their respective sizes” but even this approach doesn’t work for me.
Am I doing something wrong? Do I have to write a custom script that does what I am looking for?
Are you trying to have the orange background element automatically re-size to fit the text?
What Layout components do you have on the parents of the text object? Do you have a ContentSizeFitter as well as a VerticalLayoutGroup or HorizontalLayoutGroup?
Yes, I am trying to make the orange background element automatically resize to also contain the text.
This is the hierarchy:
Window (with Image, ContentSizeFitter and VerticalLayoutGroup)
InnerArea (with Image and LayoutElement [that ignores Layout])
ClientArea (with Image, VerticalLayoutGroup and LayoutElement)
Text (with Text and LayoutElement)
Choice 0 (with Button and LayoutElement)
Choice 1 (with Button and LayoutElement)
Choice 2 (with Button and LayoutElement)
Choice 3 (with Button and LayoutElement)
I’ve attached a small test scene wiht this hierarchy so you can see it for yourself if you want.
Edit: I’m using Unity 5.2.0f3 Personal
2390705–162862–TestProject.unitypackage (198 KB)
sigh So it’s not possible without a custom script, right?
You have to set “Preffered Size” in Vertical Fit in Content Size Fitter of “Window” instead of “Min Size”.
1 Like
@Chichkan : You sir rock!
Thank you so much for pointing that out. It works flawlessly.