How do I make my progress bar decrease with integer-based health?

Hello. I have created a simple integer based health/damage system where the enemy has 1000 health, and the player deals 100 damage per hit. However, the health progress bar widget doesn’t decrease until the enemy goes from 100 to 0 health. This is because any value over 1.0 is considered more than 100% of the progress bar. How can I change it so that it detects that 1000 health is 100%, 500 health is 50%, etc… Is there any way I can override the progress bar’s percent progress so that it has a larger value range than 0.0 - 1.0? If not, how else can I fix this problem?

You need floats for that:

Any of those 2 will work, there might be more ways…

I’m not exactly sure where to add this in. Would it go in between the subtraction node and set enemy health node?

Or do I need to add it to the BeginPlay event and set the health there?

But your health is not integer… it’s already a float. Divide current by max and you have a 0-1 range. Send that to the widget progress bar.

You can do the division when you send it to the widget, or even in the widget itself.

I changed the health back to a float because your initial comment said I needed floats for it. By “send it” do you mean cast it to the progress bar widget?

I don’t know how you organised you widgets but if the health bar belongs to the enemy, there should be no need for casting.

Are you using a widget component or a normal 2d widget?

A widget component

It’s this then.

Ah, I mean you can convert int to float and back but it can be inconvenient - extra nodes are needed. You need floats for fractions. So you main health can be an int but it need the decimals for the progress bars, alphas and many other things.

Okay. What widget is supposed to be the target for the “Get User Widget Object” node?

The widget component that the enemy is using. You said you were using a widget component.

Widget component hosts a traditional widget inside. We give the enemy actor full access to the health bar widget. So we can push in new health values and update the widget only when the health values changes. Quite an efficient approach.

If I set it up like that, I can’t execute both event paths after those nodes.

You don’t want to hook it up here. Do look at my screenshot above carefully.

Create the reference on Begin Play first - and only once - as I do, the top bit of my screenshot. Then you’re free to update the widget whenever you want using just the reference.

Also, if you ever need to have more than one execution node:

336166-screenshot-8.png

Is this looking right?

No. The division is reversed. Current / Max

But you don’t need to call Update Health (don’t connect it for now). We’re already updating the progress bar…

I don’t know what you do in that function, you might be overriding the value you set in the progress bar.

Just realised I posted an identical setup half a year ago:

Old habits die hard.

Okay, I changed the division. This is my update health function:

And here’s an example similar to yours that uses a custom event in the widget:

You’d need to add the widget component bit to this.