Creating bindings for health and stamina

To create the binding of the health variable with the Health bar UI, follow these steps:

  1. In the HUD Blueprint Editor, find the Hierarchy panel and click on the Health bar object nested underneath the Player Stats Bars object.
  2. With Health bar now selected, locate the Percent field in the Progress category of the Details panel. Click on the Bind button next to Percent and select Create Binding, as shown in this screenshot:

  1. The HUD Editor will switch from the Designer view to the Graph view. A new Function has been created, allowing us to script a connection between the meter and the player's health variable. Right-click on any empty graph space, and add a Get Player Character node.
  2. Drag a wire from the Return Value output pin of the new node to empty space, and add the Cast To FirstPersonCharacter node.
  3. Break the execution pin connection between the Get Healthbar Percent 0 and Return Node nodes, and instead, connect Get Healthbar Percent to our casting node, as shown here:

This combination of nodes retrieves the player character object for use within the HUD Blueprint. However, any custom Functions or variables we created for the player character in the FirstPersonCharacter Blueprint will remain off limits until we cast the player character object to the FirstPersonCharacter Blueprint. Remember that casting works to check and ensure that the input object is the specific object you are casting to. So, the preceding combination of nodes is essentially saying that if the player character is a FirstPersonCharacter, then allow me to access the FirstPersonCharacter functions and variables tied to that player character.
  1. Next, drag a wire from the As First Person Character output pin to empty grid space, and add a Get Player Health node. Finally, connect the Cast To FirstPersonCharacter node execution pin to Return Node, as shown in the following screenshot:

  1. That's all we need to do to connect Player Health to the Health bar UI. We need to follow the same operation for the player's stamina. Click on the large button in the top-right of the screen labeled Designer to return to the Canvas view, and then select Stamina Bar in the Hierarchy panel. By following the steps outlined previously for Health bar, create a binding that connects the FirstPersonCharacter variable of Player Stamina to the meter:

  1. Compile and save your work. If you click on Play, then you will now notice that the health and stamina meters are filled in with red and green bars, respectively. The next step is to hook up our bindings for the ammo and goal counters.
..................Content has been hidden....................

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