Trying To Create Armor + Health System for a Top Down Game


I am currently working on a project with a small team (4 people) and my role is to work on the UI elements. I’m trying to create an Armor and Health system using progress bars (I’m still extremely new to developing with UE4) and have followed some tutorials but I can’t quite seem to get it to work so I’m reaching out here in the hopes that someone does. The idea behind it is to have the Armor bar deplete before the Health bar does, and with my current blueprint, the armor depletes but the health does note. My BluePrint is pictured here:

I have a current Health variable set to 100.0 and an Armor variable set to the same value and have it set up this way so that I can easily add more damage percentages (10% and 25% for example). I’m not 100% sure what I’m doing wrong, as my blueprint looks sound. I have also tested my Health variables by binding the F key to a function that reduces Health by 25% when pressed and it works as intended so I’m fairly certain it has something to do with this function.

I appreciate any time and effort gone into helping me understand how to fix my issue.

Hi Nuclear,

Looking at it, your Blueprint may be failing at a few points. One is the Condition.
The Branch is reading your code this way: If Armor is less than 0, execute True. However, will the value of Armor ever be less than 0? If you deplete armor by 5%, you’re going to end up going down to 0 and not subtracting any more values, so your Branch will never run because it needs to be LESS THAN 0, not at 0 (using =< or == 0 would work).
Though, with that said, there’s also the issue of the True execution.

Setting Armor to 0 at the end breaks your code because of the aforementioned Branch issue. Your code is never going to fire even if it reached True because once True executes, Armor is set to 0 and therefore the Branch will never be True again.

Also, when you execute true, you’re adding Armor and Current Health. This ends up creating an issue with the Health value. You already have a variable for Health. Don’t add it to armor.
What you’re doing right now is this: Armor = 0, Current Health = 100, Set Current Health to 0 + 100 = 100.
It’s unnecessary to add the two together as the sum value doesn’t create a value that you need. You already have the value of 100.

Lastly, where is this Function being fired? Is it being fired in a DamageVolume/Enemy Class?

To explain this all better, I’ll setup some Blueprints and provide images for you of the Progress Bar to Player to Damage communication. Will maybe be a half hour or so while I get everything setup.

I know you have some stuff setup, but I’m going to start all the way at the beginning of this in order to keep things streamlined and simple.

Even if you’ve already done some of these steps, I will say just do them over again.

Just for the first run through, I suggest you go with the values I have down that way you can see how everything works then afterwards modify it to your needs.

First you’re going to want to create two Float variables in your Character class, one for Armor and one for Health. Set them both to a value of 1.0.


Step 1

Create a UMG Widget and call it ProgressBarExamples.

Drag out two text blocks, and edit the text in one to say Armor and the other to say Health.

Then drag out to Progress Bars. Do NOT change the Percent value in the Progress Bars in the side options (you don’t need to do that, we’ll fill them through variables).

All you need to do is click on one of the Progress Bars and look for the drop down box that says BIND, and click Create New Binding (It’s where the Red Line I editted in is)

(In this image you can see I already have a Binding set; if you create a new widget it will just say Bind and won’t show a Name).

Step 2

When you click Create New Binding you’ll be sent to a Graph.

Drag out from the Function output and search for Cast to [Your Character Class].

Drag out from As [Character Class] (here it’s AsThirdPersonCharacter) and search for Get Armor. Connect the Armor variable to the Return Node.

(Also be sure to set the Object of the Cast node to Get Player Character)

What we’re doing here is communicating directly with the Character Class so we can get the Armor and Health variables.

In the above example, I’m setting the Armor Progress Bar to equal the Armor Variable in the Character class.

In other words, the Progress Bar will be filled based on the value of Armor.

Since we set Armor to 1.0 in the Character Class, the Progress Bar will be filled 100% when its called to the Viewport.

Now, go back to the Designer tab of the Widget, click on the second Progress Bar and repeat these steps, but instead of using the Armor Variable, use Health
(The function should look exactly the same except where “Armor” is, Health will be)

Step 3

Now minimize that UMG Widget, and create a new one called YouDied.

Add a Text Block to the middle of the screen that says, you guessed it, “You Died.”

This is so we can test the Armor/Health depletion in the Character Class. When Health reaches 0, the player should die and this Widget will be called to the screen.

Step 4

Go to the Graph tab of the YouDied widget and drag out from Event Construct.

Cast to the ThirdPersonCharacter and drag out a Disable Movement node from the As [Your Character] pin.

What we’re saying here is that when this Widget is called to the Screen, then the player will no longer be able to move (because they’re “dead”).

(NOTE: This is ONLY for testing purpose, if you really want to disable movement, it’s better to use a Set Movement node because then, if the Player clicks a button that says “Continue,” you’ll be able to switch movement input back to true. Here we’re permanently disabling movement and never switching it back)

I’m going to stop this here for one second and put in the next few parts in a separate post. This forum gets a little iffy when I put in a lot of images and text…


Step 5

Go to your Character Class now and Create a New Function. Call it DamagePlayer.

This is going to take our Armor and Health variables, subtract a value from them and then set the variables to the new value.

First, get the Armor variable and drag out; search for a Float > Float node.

This node is going to be our initial check.

What are we checking for? Whether the game should subtract from Armor or from Health.

So what we’re going to be saying is this: If Armor > 0, subtract from Armor; If Armor == 0, start subtracting from Health.

From the > node, pull out the bool pin and create a Branch node.

Get the Armor variable, drag out, find Float - Float. Set the second Float value to 0.25.

Then drag out a Set Armor node and attach it to the Float - Float node AND also attach it to the True Execution of the Branch node.

What this does is simple: When the function runs, if Armor is not 0, it’s going to deplete armor by 0.25.
The first time this runs it will be 1.0 - 0.25, then the next time it will be 0.75 - 0.25, etc.

Go back to the Branch node and next to the False Execution, get the Health variable.
Repeat the above steps, this time with Health and ensure that Set Health is connected to the False Execution.

Let’s just review this quickly:

When the DamagePlayer Function runs, it’s going to encounter a Branch.

The Branch will check if the player has Armor (if Armor is above 0), and fire.

If Armor IS above 0, the Armor will take damage.

If the Armor IS NOT above 0 (i.e. if Armor = 0), the Health will be depleted.

Now there’s one more thing to do here…

Go back to Set Health and create another Branch.

Something we need to check for is whether or not Health = 0. If it does, we want to display the YouDied widget.

Get Health and create a Float = Float node. Set the second value to 0.

Attach that to the Condition of the Branch node and on the True Execution, add a Create Widget node, choose YouDied, and then from the Return Value create a Add to Viewport node.

When the value of Health reaches 0, the Player will see the text “You Died.”

Step 6

Close that and create a new Blueprint Actor. Call it DamageVolume.

We want a way to test our code, so we’ll setup an Actor that will cause Damage to the player in some way.

In the Components tab, add a Box Collision. SCALE the Box Collision to be pretty large, then also add a Cube Mesh.

Put the Box mesh in the center (this isn’t needed, but it’s just helpful so that when we put it in the level, we know where to step).

Step 7

In the actor’s Graph click on the Box Collision on the left hand side under Components, and create a new On Component Begin Overlap node.

Cast to your Character class and from As [Your Character] drag out and search for DamagePlayer.

This is a simple check system.

What’s going to happen is that when the player enters the Box Collision, DamagePlayer is going to run. At first it will subtract 0.25 from the Armor until Armor = 0, then it will just depleting Health

Now this check is admittedly a bit tedious. Because of how the Overlap node is setup, you’re going to have to step into the Box Collision, get the Armor damaged by 0.25, then step out and step back in again. If you do that 4 times, Armor will equal 0 and the 5th time you step in, it will start to deplete Health.

(You can make this loop so that as long as you’re in the Collision it will deplete the Armor every second but since we’re not looking at Timer loops right now, I won’t go into all that).

Step 9

Place your DamageVolume actor into your level and then Press Play.

Walk into it once and Armor will be 0.75

Step out, walk in again and Armor will be 0.50

Step out and walk in again and Armor will be 0.25

Step out and walk in again and Armor will be 0.0

Step out and walk in again…and Health will be 0.75…

That’s all there is to it. That’s the very basic way to create a distinction between Armor and Health.

I hope this helped. If you have any questions, leave a comment here or PM me if you need.

Good luck!

That worked! Thank you for taking the time to help me understand what I did wrong and how I can achieve what I wanted to. I also appreciate your taking the time to thoroughly explain how to fix what I’ve done so it works correctly, but wanted to apologize for the late response. For some reason, I couldn’t reply to the topic yesterday before I headed out to work. I think next I’ll take your advice and expand on that YouDied screen to allow additional functionality to restart the game. Thank you so much!