Scrolling Areas in New Unity GUI

I spent a lot of time yesterday trying to get a scrolling area of indeterminate-size text working on my GUI - searches come up with several solutions, none of which worked, mostly because they always involve at some point adding a ContentSizeFitter to an object that's a child of the ScrollView.  Unity complains about that as a conflict, and understandably so - the ContentSizeFitter does get the text to resize to it's contents in principle, but the parent always seizes control of the RectTransform and so won't let it do its job.

(The Unity manual says the solution to this is that the ContentSizeFitter isn't necessary, and that 'The parent Layout Group can already make each child fit the size of the content.'  But this is A MALICIOUS LIE.  You can fiddle about with settings on the parent Layout Group for a whole hour - believe me, I know - and if there's not a ContentSizeFitter on the Text object, that text ain't expandin'.  Although one thing the Layout Group might do is shrink the text to a height of zero.  You know, just to show it's joining in with the fun.)

But as it turned out, all this fiddling was unnecessary.  At some point (whether in Unity 5.2, or in a previous update that I didn't download) a new menu option has appeared to add in a fully functional ScrollView with all the required child objects in place so that you don't have to do it manually - and it's certainly doing its job a lot better.  Since I only wanted one Text object in my scroll view, I put that in place of the empty Content object it automatically creates, and replaced the reference to it in the ScrollView.  The Text object now accepted a ContentSizeFitter, and everything was fine.

I presume the automatically generated ScrollView is a new feature since all the help I spent hours searching for online yesterday didn't mention it, and only mentioned hacky solutions like the ones I was trying myself and which either didn't work or required a lot of scripting (and while I've been prepared to do that for one scrollview, I'm not accepting it when I've got a few dozen of them to do).  So there is now, in any case, at least one online mention of the easier solution that now exists.

This entry was posted in Unity and tagged , , , , . Bookmark the permalink.

Comments are closed.