I’m trying to create a chat box and recently tried using the content fitter component. The when set to preferred it is using the minimum size possible when the scene starts. Any additional text does not cause it to expand in any way.
If I want to add text I need to disable the content fitter, reset my rect transforms, add the text, and then re-enable the content fitter. It then uses the minimum size rect to fit my text, and will not expand after that if I try and add more text.
No matter how many times I play the scene I don’t even get consistent results from the preferred height of my text box. It seems that the text I input into the text box does not show up unless I manually edit the text area in the inspector.
Thanks for the reply BoredMorman, I definitely have to call ContentSizeFitter.SetLayoutVertical() for it to resize itself, not entirely sure why it doesn’t want to play ball. Just figured out the pivot thing myself an hour or two ago!
I have just encountered another issue with the Content Size Filter. If I am using Rich Text, it does not seem to resize at all, even when calling ContentSizeFitter.SetLayoutVertical(). I can intermittently get it to resize by disabling Rich Text for the text box, calling that method, and re-enabling rich text. I mentioned intermittently because sometimes it does not resize, and it takes multiple disables and re-enables of rich text to get it to resize itself.
I honestly can’t make heads or tails of it. If you don’t mind providing me with some assistance I’m definitely willing to give you anything you want from the project that would be necessary to figure this out. Been puzzling over this one for quite a while.
Edit: It seems that the preferred height for the Text component does not change as I add text to it. However the text is definitely in it’s Text.text property, I can debug and see it, as well as manually drag the RectTransform down to display the text inside. Disabling and re-enabling the Rich Text seems to periodically facilitate a change in the preferred height. I imagine there is a method inside the Text class that is triggered when the Rich Text is enabled or disabled.
Edit 2: I suspected it may be a method in the Text class that waited to late in the frame to run, if I make a coroutine: