Setting up a project
To get started, start Unreal Engine 4 and create a new project based on Third Person Template.
Since we are going to have a HUD with a health bar, let's add a new health variable to our Third Person Character Blueprint. Open up the ThirdPersonCharacter Blueprint in the ThirdPersonBP/Blueprints
folder:
Inside our character Blueprint, create a new variable called Health and follow these steps:
Set the variable type to
float
and give it a default value of 100. The next step is to create a Pure function that shows the percentage of the total health of the player.Inside your Character Blueprint, create a new function (for example, GetHealthPercentage) and open it.
In the function graph, get your health variable and divide it by the default value of health. By doing so, we will get the percentage of our player health. To get the default value of any variable in your class, just right-click in graph and search for Get Class Defaults. This node will return all the default values...