Making the non-scrolling dimension of a ScrollRect match its contents

Hey all,

Sorry if this has been asked a million times before, but searching has failed me.

What I have:

  • A dynamically created vertical ScrollRect with viewport and contents objects, containing dynamically created children. This does scroll properly

What I want to do:

  • Also have the width of the ScrollRect match the preferred/min width of its contents.

Is it possible to do this with Unity’s own scripts?

1 Like

I’ve been wondering the same thing, it feels like unity’s scrollboxes are too complicated for their own good, I’d almost be better off making my own XD

you could go through the children and get the highest min / preferred size and then use that in your scrollrect

or perhaps the content size fitter component will be usefull for this when applied to the scroll rect