Hi guys,
after months of using it, once in a while the UI system still surprises me with something unexpected. This time is with the nefarious Content Size Fitter + Horizontal Layout Group combo (i’ve seen plenty of posts of people struggling with it).
I am building up a tooltip system that can change size correctly according to the length of the text it contains.
(using this approach Redirecting to latest version of com.unity.ugui)
so I have
Image (with ContentSizeFitter and HorizontalLayoutGroup)
- Text
It works perfectly as long as I don’t assign any source image to the image (so i leave the default white thingy). If I assign a source image, the tooltip gets stuck in the fixed size of the image i drag and drop there from the inspector.
In searching for an alternative solution, i also made a different test setup
Image (background of the tooltip)
- Empty UI element (with ContentSizeFitter and HorizontalLayoutGroup)
- Text
And I tried to change at runtime the size of the root element by retrieving the preferredWidth&Height of the HorizontalLayoutGroup (i know it’s hacky, but i am trying for a solution). The weird thing here is that not only it doesn’t work if i read it on Start(), but it only works on the 2nd Update call (the first still shows 0,0 as preferredW&H).
Is there any clean way to do this or a workaround is the only way to go?
Cheers,
Emiliano