Feb
23
2016

UI Scroll View automatic Content height

“Hidden” inside the docs ( http://docs.unity3d.com/Manual/HOWTO-UIFitContentSize.html ) you can find details how to make UI ScrollView content to have automatic size based on the child objects. Here’s images how to use it:

– Add “Vertical Layout Group” and “Content Size Fitter” components to the Content gameobject,
– Set “Vertical Fit: Preferred Size” Now your scroll bar will stretch to correct size

unity_ui_scrollview_automatic_content_height_1

– Then your Text gameobject will also have automatic height (enter any amount of text, even if Text “Vertical Overflow” is set to “Truncate”)

unity_ui_scrollview_automatic_content_height_2

*Note: If the Scroll View cannot be scrolled (as if its locked), then add UI/EventSystem to your scene (it was missing on those screenshots)


20 Comments + Add Comment

  • It helped me a lot! Thanks! I just found out your blog and Im starting to dig in! Lots of cool stuff. If I have any question about your posts are you willing to answer them? 😛 Cheers!

    • Hi, yes of course, if can (but if its some generic unity question better ask in unity forums, will get more answers there)

  • that took me forever, thanks alot

  • Great!
    Worked but I had to activate “Child Control Size Width + Height” that it worked!

  • very helpful, thanks

  • still perfect , thx !

  • I can’t seem to get this to work in 2017.3.1f1. The Text scrolls but it’s jumpy and skips over blocks of Text. Do you know if anything has changed?

    • I have the same problem, any ideas?

      Thanks.

      • i tested with 2018 beta 11, didnt see any issues.. can you post gif how it looks on yours?

  • Seems not to work when the blue marked Text Gameobject has a child and this child gets resized.
    Tried on 2018.2.8

  • Thanks so much! Really helped me out. First time I read it I somehow missed the first step, but afterwards came right.

  • very Helpfull

  • thanks man

  • Worked. Thanks.

  • Very helpfull.
    Thank you.

  • 4 1/2 years later and Unity still hasn’t just default added the Content Size Fitter component to the Content component. It just seems like that would be the common use of the thing! The documentation isn’t clear at all and probably should include a hint. Instead, game developers spend half a day trying to figure out how to access the rect transform height and modify it with a clever algorithm based on actual content (not the component) size to no avail!!

    In 2020, this blog post is still as helpful as it was at the time of writing.

    Thanks!

  • Short and sweet explanation that helped me out. Just want to add for others looking this up, note that the scroll view itself (not just the content within it) is also a static size by default.

    In many layouts you want that, but if you want the scroll view to be dynamic too (so that it resizes to different screens) then make sure to change the scroll view anchoring to Stretch.

  • thank you . exactly what i was looking

  • Greetings from 2023 – still useful to this day! 🙂

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.