Is there any way to get a Panel to resize dependant on the length of text in the Text component childed to it?
Yes, just add a ContentSizeFitter to the panel.
The job of the content size fitter is to alter the Rect Transform of a GO to match the size of it’s children.
I am using a Content Size Fitter or a Panel in order to fit the size depending on the amount of items I have in a list, this is so I can use the Panel as the content item for a Scroll Rect, but it isn’t fitting the vertical size of the list, no matter what I set the enum in Content Size Fitter/Vertical to.
Make sure you also set the “Vertical Fit” to “Preferred size”.
Just tested here with
- Canvas
- ScrollRect (Scroll Rect)
- Content (Vertical Layout Group + Content Size Fitter - set to vertical / preferred)
- Lots of Child Text components
Every time you add a new child Text component it expands the Content RectTransform within the scrollRect