Content size fitter and scroll rect

Hi!

I have this area that loads levels and for each level there is a button. I need the scroll area to expand for each button. I asked that question before and they said I should apply a content size fitter to the content and it seems to work at first glance. But then when there is more levels then the content can fit nothing happens. The scrollbar doesn’t expand and the content doesn’t expand. What should I do? I have both the horizontal and vertical fit on Preferred Size. How I do I get it to expand for each button?

Thanks in advance!

Hi RealMTG,

I put an update on the original post when I saw this. You’re right my solution did look like it’d work but when you try to scroll it doesn’t I hadn’t noticed as I just dragged the content page which did move and snap back.

I’m currently trying to get mine to work, it’s almost there but not quite. For me the following line:

scrollArea.offsetMax = new Vector2(scrollArea.offsetMax.x, (MenuItemCount * 223));

Works, as I create each item it dynamically increases the size of the scroll panel by increasing the MenuItemCount by 1

MenuItemCount = MenuItemCount + 1;

223 is just the height of my prefab with a tiny bit of padding. Just need to refine it a bit for me.

Should add scrollArea is the scroll panel that’s the parent of the instantiated objects. I only have 1 column but if you have more than 1 then you’ll need to calculate the first part of the Vector2 as well instead of just getting it’s current value with “scrollArea.offsetMax.x”.

Hope some of that makes sense.

EDIT:

Oh and the way I’m calling my menu items is really complex, it’s a list but with filters on it so difficult to get a count on the number of items I’m creating, if say you want to return everything in a list just get the .Count and set the offsetMax.y = myList.Count * prefab height to that.

EDIT 2:

And another thing I had trouble with, set the anchors of the panel that you want to scroll to the corners but the parent with the “Scroll Rect (Script)” Component on it leave the anchors in the middle.