[C#] How to script a button into the "content" of a scroll view ?

Hello,

the title already reads everything.
I am trying to build a small area, where lots of buttons will appear. But (that will be a tough one too for me) I don’t want to pre-create all those buttons, but I want to make them dynamic into the content field. Goal is to have upgrades, that have been unlocked, to appear in that scroll view, to click them to buy the upgrades.

Thanks for your help!

Basically, instantiate buttons at run time and set their parent to be the content.

1 Like

Well… you just said in other words what I want to do, but I still don’t know HOW to do it… :sweat_smile:

This should give you a start.

Basic idea is to use various layout elements to let the parent panel resize based on the number of children it has. Then you instantiate each of the children from a prefab.

2 Likes

You can use a grid layout and button prefab for instance. Add grid layout to the scroll view, and then when needed instantiate your button prefab and attach it to the scroll view using the SetParent. It should be resized and positioned automatically.

1 Like