Automatically resize scrollview based on vertical text length (Solved)

Goal: Have a scrollable viewport to display different unknown text in the form of strings, where text is constantly added to the end of it as new entries.

Method used so far: Unity UI scroll view object, with text panel as a child.

Issue: When text is added to the existing text child, the object holding it does not expand with the text. The scroll bar only scrolls for the objects height and does not consider the texts actual height

Probable solution: Something that checks how much physical space the text takes up, and resizes the game object to that size, or something around there.

Additional Info: Ironically, the input field where I’m typing my question is almost exactly what I’m shooting for. As you write more text, the scroll bar gets smaller and smaller and lets you scroll over larger areas.

EXAMPLE TEXT: (It’s basically like an ingame console)

You: use item

Invalid command

You: use item2


Okay. There’s a game component called “Content Size Filter” that does exactly this. Just add that as a child to the panel and it does all the work for you.

can you expand please (pardon the pun!)

I have tried adding a content size fitter to, ViewPort (but gets disabled due to layout group of parent), Content and text game object within Content.

Nothing makes the content container size dynamically to the text child within?