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
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.
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.
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:
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:
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:
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.
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?