4.6 UI : How to automatically set the size of a pannel from the size of inner text or other elements

Think like a modal window opens and depending on it’s amount of text or buttons inside it resizes accordingly.

Any tutorial is appreciated too.

Thanks :smiley:

Lets take a simple example, add a panel to the canvas and add a Horizontal Layout Group. Untick the Child Force Expand for both width and height. Also add a Content Size Fitter and set Horizontal to preferred. Set padding left and right to 5 so the text has a bit of space around it (just personal preference though).

Add a Text UI element as a child of that panel and again add the Content Size Fitter and set Horizontal to Preferred.

Now when you add or remove text the whole panel will expand. Sure I came across someone working through a tutorial for a modal window that uses this for more complex boxes as well so maybe search for that video.