Collating widgets into an array

Within my inventory widget I have 36 inventory slot widgets that need to be placed into an array called inventory slots, what is the best way of doing this?

129817-screenshot003.jpg

I know I could use the add node to add them one by one but is there no way to use something like a foreach loop or get all actors/widgets of class to add them all at once?

I don’t think there is an automated way of doing this other than using a make array node and dragging each reference, then promoting the array to a variable on construct.

Another thing you could do, is make the slots in a separate widget blueprint. Then on construct use a create widget node on a For loop that adds a certain number of those image widgets to whatever their parent is, vertical box, or whichever. As it’s doing that you can add them into an array. That makes more sense if each has the same basic layout. If you add some variables to your image widget blueprint, such as texture and an integer to differentiate it from the others (or any variable you need), make those editable and exposed on spawn, then as they are being created you can pass those variables into the widget. Also add a reference to your main widget using the Self node, so they can call functions on the main widget if needed.

That’s similar to what I’ve done in the example below:

That’s adding buttons to a scrollbox, and passing in the needed variables as they are created.

This is useful if the amount of images in your inventory changes, if it’s always the same amount it would probably easier just to manually put them in an array.

I would recommend just adding them into your inventory as you spawn them, it would be the most efficient I guess. Although, I am pretty sure what you are asking for also is possible.