Help with level up reward options

Hey ! So I’m a bit new to Unreal Engine. For the past week I’ve been working on a survivorslike and I’m trying to find the solution to my problem but I’ve not managed.

Right now I have a Widget that spawns on the screen when the player levels up. The widget has 3 buttons that increase a specific player stat when clicked on. As of now they are static and the functions to increase the player stat are hard coded into each button.

What I want to do is : Have the buttons be random each time this widget is opened.
What I’m struggling with : have the correct player stat & function be associated with the correct button since it is random each time the widget gets opened.

I have been reading up a lot on how to deal with this but I don’t quite understand how. I’ve read that I should maybe use a struct for this but I’m unsure on how to implement this the correct way.

Thank you.

Hey @The_Duck how are you?

That is a really interesting question! Let me show you and explain how I would do it!

First of all I want to clarify that I tried to make the system as generic as possible so you can replicate it and add/remove stats without breaking it. In addition, I’m using variables inside the Character blueprint but you can use tables if you want. Another point to clarify is that I’m opening the widget with a key for testing purposes but you can open it with whatever method you want.

Lets start with a breif explanation of the system:

To create this widget, I choose to keep the Widget as simple as possible and manage almost all the logic inside the player blueprint. This is to avoid unnecesary back and forth of variables. We will need to create an Enum with all our stats, a Struct with the data for the widget buttons, and the widget itself.

The player will store all the variables, randomize the possible buttons and process the result after clicking on any button.

So this is the step by step:

  1. Right click on your content browser and search for “Enumeration” and create one (mine is called E_StatType):

  2. Open it and add all the Stats you want to be able to modify with the buttons (in my case they are HP, MP, DMG, DEF, and SPD):

  3. The right click on your content browser again and search for “Structure” and create one (S_StatUpgradeOption in my case):

  4. Open it and add the values shown on the following image:


    As you can see, this will be used to define the buttons on our blueprint. The first value (StatType) references our previously created Enum.

  5. If you didn’t create a widget for this, create one (we will develop it later, but we need to create it now because we will need to create a reference inside the player blueprint).

  6. Open your character blueprint and create the folowing variables (variables called “MaxSOMETHING” are the variables you probably already have) the most important ones here are Stats (which is of type E_StatType) and LevelUpWidget (which is the widget with the buttons we will be using later):

  7. This is where the fun begins! Now you need to create a function (I called it ApplyStatUpgrade), which will apply the changes to the stats when we press one of the widget buttons:


    (New Value is a local variable of type float)

  8. Now, create a function to Initialize the player’s stats and another one to sync player stats with our Stats Enum, then call them on Begin Playe event:



  9. Now the most important function for our system, the one that creates the randomness:
    A. First create these local variables


    B. Then create this function

    Keep in mind that you need to repeat the final four nodes for each stat you have (you can see the three missing lines going out of screen for DMG, DEF and SPD)

  10. Now we can open our widget and start configuring it! First of all, your widget should look like this:


    With a canvas, three buttons, an overlay as a child of each button, and one image and one text block inside each overlay. I make it look like this:

  11. Now let’s go to the widget’s graph and create a function called SetupButton to get the text and the image for our buttons:

  12. The next step is to create this 4 variables in out widget:


    Make sure you set the OptionDataArray as Instance Editable and Expose on Spawn on its details:

  13. Now we need to create a function to get and set the data for our three buttons, and than call it on the widget’s “Event Construct”:


  14. The final part is to manage the “OnClick” event for each of our buttons, you only need to repeat this code for each one of them making sure you use the right “Data_Option” variable for each button:

And that’s it for our system! The only thing missing here is opening the widget, I will show you how I did it from the character but you can implement it where you want:


Keep in mind that wherever you open the widget you will need to call the character’s “Generate Random Upgrade Options” function to be able to pass the Options to the widget, as you can see in the first two nodes of this blueprint.

Let me show you how it looks! (I added some prints to be able to test it)

Hope this helps you with what you need! Let me know if you need any clarification!