How to change the Health UI according to how much HP the user has?

I have a custom image to show the HP. it is a basic single hit = single damage and with each change of the hp i have a new image to be displayed to represent the current HP. How would i go about this?

I have set up a HPWidget blueprint for the UI but not too sure how i would set up the brush binding to work in such a way.

to start with there is 4 states, 0 hp, 1 hp, 2 hp, 3 hp. and later on i will add a function to increase the max hp all the way to 10 so the solution should be able to handle a large amount of variables

PS apologies if any of my terminology is misleading or wrong, im new to UE5. Thank you

Hey @frankydoodlies!

Try out this tutorial! It looks like he covers all the bases. Get back to us if this doesn’t do the trick, and make sure to bring some screenshots of your code so we can work with that!

Disclaimer: This link is not affiliated with Epic Games, Unreal Engine, or their partners.

This uses a progress bar and not an array of images so doesnt help

1 Like

a progress bar works by taking a percent (0 to 1) and mapping that to a widget.

You could mimic the same thing with your images. Put them in an array, get your percent of health, find the index in the image array that is closest to that, make it visible and hide all others.

2 Likes

Thank you, i will give that a try tomorrow

Consider driving it with Events - execute only when you get hit. If you bind, it will execute every frame; not the end of the world but why waste cycles. Perhaps something along the lines of is enough:

Images to show sit in an ordered array. Call the event when the player gets hit and you’ve calculated the damage done.

3 Likes

Okay, this looks like the perfect approach. will this be under my HPWidget for the UI or under the player BP?

I would calculate health (state) in the player BP and call the above script in the widget. If the state calculation is simple and nothing else needs it, you could do the entire thing in the widget.


Considering what I posted previously, the script in the player could like so:

You will, ofc, need extra bits for clamps / max health and so on but this could work just fine.

Do you have any info on how to create the array, im struggling with that right now. sorry, im very new :smiley: I really appreciate your help

image

  • if you’re unsure what type to choose, mouse over pins:

image

  • or even right click them → promote:

image

You can then turn this automagically created var into an array, as in 1st pic.

1 Like

how would i add the images?

how would i add the images?

Providing you’ve already imported them into the engine, you can set them from the dropdown. Or select the desired asset in the Content Browser first and:

image

You can rejiggle the order with the grip on the very left, and insert / delete / duplicate / elements with the tiny downwards fencing arrow on the right.


More info:

great, and im guessing the health value will relate to the index of the array.

for instance, health = 0 will result in index [0] from the array being displayed?

Aye! I should have mentioned it. Make the array as large as it needs to be. But do not allow the index to climb too high until the player’s health pool has increased.


There are other, more explicit ways to do it, but this seems more than feasible.

perfect! one last thing, originally i thought you set up the Current health state event as a blueprint interface to get the widget and player to communicate, but seems a little different. how did you set this part up?

I did not set anything up. It’s direct comms.

The player actor creates a widget and stores its reference (at the top). No need for interface / casting. Right click pins to promote them:

Now you have a reference variable with correct type. Go nuts. :smiley:

1 Like

sweet, ive managed to plug it into my system and get it all working now. Thanks for the help! Im sure youll be seeing a lot more of me around here :smiley:

1 Like

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