UI displayed through randomness and code

Hello, I am trying to make a system in my game which will show a selection of 3 random windows (which grants powerups) every time the player levels up. Now I have a paused menu pop up when the player levels up, what I need to do now is be able to add a different powerup widget to each vertical box. I have attached images of my current blueprint (there is nothing more outside of where it has been clipped), the empty UI widget with the 3 vertical boxes (ignore the test buttons) and an example of the menu with 1 of the 3 widgets on display (this is to represent the end goal, I can’t trigger this automatically yet so need pointers on that front).

NOTE: the following two posts show some bug fixes and a partial solution to the problem. The main issue to solve is how to get a widget in each box and try to avoid duplicates.



You might notice an error with my random number generator on the “RollInCommon” event. Just fixed it, overlooked a rookie mistake there.

I may have already found part of my solution:


This allows me to get the process running as soon as the UI widget activates from levelling up.

My next issue is trying to create 3 of the powerup widgets with one in each vertical box (and avoiding duplicates). Any suggestions greatly appreciated.

Do you have one widget for each possible powerup (like WB_Buff_Health) ?
If so, make an array with all all the possible buff widget classes, then shuffle the array and pick first 3 elements.


Don’t add the buff widgets to viewport. Only the parent (selection widget) should be added to viewport, then the children (buff widgets) should be added to the vertical boxes. In your selection widget, head to the designer and select each vertical box and make sure the “Is Variable” checkbox is ticked. Then your vertical boxes should be available as variables in the bp graph. You can get them and use “Add Child” to put your created buff widgets into them.

That’s what I am doing, my issue is I don’t know how to display it on the positions represented by the 3 vertical boxes.

Well I should clarify I plan to run 2 more iterations to get all 3 widgets showing but first I need to get the widgets to display in the right place.

Really appreciate the visual example, I tried to replicate it in the context of my own code (so instead of doing the shuffle I am calling upon my item rarity rolling stuff as I want some things to have different chances of appearing) but it seems I have plugged things in improperly:


What happens is I get a window showing up in the middle box only, I assume it has something to do with me not using the array index from the for each loop but I have no idea how to link that in. Perhaps I have got this all completely muddled, still relatively new to working with Unreal so I have plenty to learn.

You are not adding any child to the box. You need to create a widget (a buff widget) and plug the result there.

If your buffs are categorized by rarity, make one array of buffs for each rarity.
Shuffle and Index are here to prevent picking the same element twice.
If, for each box, you reshuffle and pick the first element, then you risk having two boxes with the same item. Alternatively you can remove item from the array after picking it, but there’s no much reason to do that over shuffling just once.

Here’s a less confusing version maybe, that doesn’t use for loop. It ends up duplicating lots of nodes, but maybe easier to understand for you :

Makes sense to me, how can I get the “rarity” value out from the “RollRarity” call?
image
I am guessing some form of return statement?

Edit: I made a work around for my RollRarity event which set an integer correlating to the rarity’s position in the array, now it all runs smoothly. Massive thanks for all your help!