Hi, I'm Adam. Email me about: CTOs, Mobile/iOS, Project Management, and Development

Unity UI – making Scrollview work perfectly WITHOUT ContentSizeFitter

I’ve always found ContentSizeFitter a source of great hope … and bitter disappointment: often it’s the only way to “solve” a problem in UnityUI, but half the time when you try it messes up your UI and breaks the UnityEditor Undo function. You have to delete your UI elements and rebuild them from scratch :(.

Unity’s own staff have pointed out on the forums that it only works in limited scenarios (some of what we think of as bugs they’ve explained as side-effects of Unity’s built-in layout algorithms, which make it “impossible” to expand content to fit. That’s not entirely true, since Flexbox4Unity is able to do all of these, and it’s embedded inside the Unity system :), but I agree the core Unity layout alogirithm isn’t great).

CSS/Flexbox has a much better layout algorithm (and a free, open-source, speification that anyone can implement). In the Flexbox4Unity plugin, this works nicely, and auto-resizing / size-to-fit UIScrollviews just happen “for free”, every time, no problems. I’ve posted a guide for setting up UIScrollviews this way inside Unity: http://flexbox4unity.com/2020/04/08/guide-automatically-resize-uiscrollview/