Creating simple UI meters with UMG

The creation of UI elements is done in the UMG, which is a visual UI authoring tool. We can use the UMG to create a menu and game Heads-Up Display (HUD). A HUD is a kind of transparent display that provides information without requiring the user to look away. We want to show meters on the HUD with the amounts of health, stamina, and ammo the player currently possesses. These meters that appear on the HUD are known as UI meters.

To create a HUD that will display the UI meters for health, stamina, and ammo, we will first need to create variables within the player character that can track these values. Before doing so, ensure that the box labeled Instance Editable is checked so that other Blueprints and objects can manipulate the variables. When a variable is made editable, it will be shown with a yellow open eye symbol next to its name in the Variables section of the My Blueprint panel. Now, to create simple UI meters, follow these steps:

  1. Open the FirstPersonCharacter Blueprint from the Blueprints folder of your project. Within the Blueprint, we are going to define variables that will represent additional states that the player and game will care about.
  2. Find the Variables category of the My Blueprint panel in the Blueprint Editor. Click on the + sign to add another variable, and call it PlayerHealth.
  3. With PlayerHealth selected, find the Details panel and change Variable Type to Float.
  4. Follow the same steps again to create a second Float variable called PlayerStamina.
  5. Next, create a third variable, but this time, select the Integer variable as Variable Type and call it PlayerCurrentAmmo.
  6. Finally, create a second Integer variable called TargetKillCount and compile the Blueprint. The result of the player variables should look like this:

Now, we need to set the default values of our four new variables. We can do so by clicking on each of these variables and changing the field under Default Value in the Details panel. I set PlayerCurrentAmmo to 30 and TargetKillCount to 0, but you can tweak the default values to whatever you think is appropriate for your desired game experience at any time. PlayerHealth and PlayerStamina should both be set to 1.0, as we will represent those with UI meters that will display the degree of fullness between 0 and 1. Once you have set the defaults, compile and save your Blueprint.

Now, we will learn about how to draw shapes that represent UI meters.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset