# Why does this health bar not work right?

In the game instance I created a Player01Health variable (integer) and set its default value to 100.

In my third person character I set up logic for the player to receive damage and even death from the enemies. In the following the damage variable is set to 10.

In my widgetHUD, I added a progress bar, colored it red, and bound it.

When I set the variable, the game shows a completely empty progress bar.

However when I take the set out, the game starts with a full health bar, but after just a few punches from the enemy, the bar immediately goes empty and it does not increment to nothing.

Any ideas? Thanks!

edit: In regards to the last image

Make a new divide node but of type float / float. In the bottom half put in 100 and hook up the top part to â€śPlayer01Healthâ€ť. This should make it go from an integer to a float via a conversion node. Then get the result of the division (a float) and hook it up to the return node.

You bar is emptying at once because youâ€™re not getting fractions but ints

You could also use the map ranged node

InRange A = 0
InRange B = max health
out Range A = 0
out Range B = 1
and plug the return value to your progress bar

Yep, that was it, thanks!

But honestly I donâ€™t understand why the integer did not work. If Iâ€™m subtracting 10 from 100 and not using decimal pointed numbers, then the health bar should have subtracted a tenth of the health bar everytime. Oh well, maybe the progress bar has to be a float for whatever reason? Thanks again.

Unreal doesnâ€™t internally convert int to float so there is zero precision when it comes to the division.

Itâ€™s a hard lesson to learn and reflects more on programming fundamentals (differences between, int, int32, float, double etc). They all have their own properties and to do division you need precision (you lose the max limit a variable can hold but you get fractions in return)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.