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
– Then your Text gameobject will also have automatic height (enter any amount of text, even if Text “Vertical Overflow” is set to “Truncate”)
*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)
Related Posts
20 Comments + Add Comment
Leave a comment
Recent posts
- MotionVector Effect: Object “disappears” when paused
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
Recent Comments
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
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!
fit image to text bounds
https://aillieo.cn/post/2019-05-22-unity-3d-notes-05/
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! 🙂