I have this simple structure inside a Canvas:
Now, it works pretty well, when the text gets out of boundaries, the UI-Image expands. But since I have a Layout Group as a parent to my TMP Text, I get an error inside the Text, in the Content Size Fitter, saying that 'The parent has a a type of layout group component...'. And as a result, the image height sometimes doesn't update when I the text changes (doesn't grow or shrink, only after I refresh or save the project).
Am I doing something wrong here?
I will convert this to answer since I'm going to attach images. I did something similar to this for a chat feature.
Make the parent have the content size fitter and set either the horizontal or vertical fit to preferred size.
Let its immediate child be the background, and add a layout element to it to control its minimum size. Also add a layout group to it to control the text that you will put as a child to it.
Add the text as a child of background
Change the text to check the background.
[EDIT]
1. I changed the Parent's layout group to VerticalLayoutGroup
.
2. I made a duplicate of the game object "Background" but with different texts to that you can see how the ContentSizeFitter
and VerticalLayoutGroup
controls the size of the children.
In the screenshots above, I never adjusted anything on the rect transform. I just changed the text, and as you can see, the background of each text/dialog/message also adjusted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With