- Home /
Scrolling list of prefabs
I have an equip screen in a game I'm working on and will have a list of inventory displayed for the player to choose from. I'm displaying the inventory options in a list. All of the available inventory, even when filtered down, will be more than can be displayed on a single screen and so I need to make the inventory list scrollable.
I'm using the new UI controls to accomplish this and am most of the way finished implementing the solution. I have a Scroll Rect, Scroll Bar, Vertical Layout Group and Mask to achieve the affect. Each inventory item in the list is a prefab.
The only real issue I'm having is that when I add a prefab to the panel that is being scrolled and masked I can't find a way to make the panel size taller to accommodate all of the inventory item prefabs. In practical terms the problem this causes is I can only ever see as many prefabs as will fit in my panel at a static height. I would like to be able to add an indeterminate amount of inventory items to my list and have it automatically increase the scrollable area.
Is there a way to tell the Vertical Layout Group to automatically expand to meet the size of the contents? Or is there a better way to do this? Even though the mask would hide this from the user, it seems wrong to make a panel that's 20,000 pixels tall to be the height of the contents.
Here is an image attempting to show the problem I'm having. The lighter background of the prefab at the bottom indicates the one that the scroll rect won't automatically show. It can only be seen if I set the Movement Type to Elastic and pull the list away from the bottom of the ScrollRect.
Appreciate any help anyone can provide.
Answer by omatase · Feb 19, 2015 at 01:55 AM
Aaaaaaaaaand I find the answer five minutes later.
After posting the question I resumed my research and found what I think is the best solution. Here is a link to another stack overflow answering a different question. The solution, however, works for my problem as well.
http://answers.unity3d.com/questions/789561/46-ui-text-rect-does-not-expand-automatically.html
Your answer
Follow this Question
Related Questions
stopping scrollrect if it is about to leave the desired space 0 Answers
Masking GameObject in Canvas 1 Answer
Use a UI Mask on ParticleSystem 1 Answer
Scroll Rect in Web GL 5.4 0 Answers
Strange scrolling behavior of a native web view on iOS 2 Answers