I was wondering if anyone can help me set up a heart-based health meter? I’m not looking to make something as elaborate as the one in The Legend of Zelda games which features things such as damage being managed in partial hearts or multiple rows of hearts that I’m not interested in. I just want a simple single-row, heart-based health meter that displays health as a series of heart images that as the player takes damage replaces the whole heart images with empty heart images, like :
I also need to be able to upgrade the health meter to increase the number of hearts displayed up to a total of 9.
I’ve tried looking up various tutorials on how to set up such a system but all the tutorials I’ve found so far tend to be based on The Legend of Zelda’s heart display system. I just find such tutorials to be overwhelming as I lack the know-how on how to modify these setups to suit my own purposes.
Easier said than done, by following [ tutorial video][1] I’ve been able to add finally a visual heart display to my game HUD but only the visual part.
Unfortunately, once the tutorial reaches the how-to of implementing the actual functionality of the health meter is where I get stuck, as the tutorial’s implementation involves percentage-based material that isn’t of interest to me and only serves to make things extremely complicated.
All I want is a relatively simple, upgradeable heart-based health system based on rudimentary addition/subtraction but as it stands right now, is all I currently have:
Can anyone please help? I know that the coding for connecting the heart meter to the rest of my health/damage system should go where the Print String node is but that’s about all I know.
Based on your images above, every time you take damage or gain health, you want to iterate your array of HeartWidget, and change its texture/material based on whether it should be filled or empty.
Your HeartWidget needs to expose the element containing the texture (most likely an Image element) by checking Is Variable on it.
Then, instead of PrintString, access your HUD, and iterate HeartWidget with a ForEach loop. For each widget, get its Image element, and set its texture based on the condition whether it should be filled or not : If ArrayIndex > Current Health then use empty heart texture, else use filled heart texture.
Something like (incomplete example, just showing you the general idea)
Thanks for the response but I’m extremely confused as to what you mean by accessing the HUD instead of PrintString. Did you mean put all the above code into the HUD blueprint and call it by custom event where the PrintString node goes?
In addition to that, I’m having a couple of other issues as well that I need help with.
Firstly, in your example, you have a reference to the ‘Current Health’ variable connected to the ‘Greater Than’ node that I can’t seem to replicate for some reason. Every time I’ve tried to ‘Get Current Health’, I instead up with :
Not helping matters is that its been a while since I’ve done anything with Unreal so I’ve forgotten a lot about what I’m supposed to do in matters like .
In addition to my above confusion, I’m also having problems with changing how the hearts are displayed. The problem I’m having stems from the fact that I can only attach the Heart widget to Set Brush from Material which is a problem because the actually heart images are textures not materials. I can connect the Select node to Set Brush from Texture but not the Heart widget, as the Set Brush from Texture node says the target needs to be a “border”, whatever that means. Whereas I can connect the Heart widget to Set Brush from Material but not the Select node, as the textures are incompatible with that node. The Set Brush from Texture Dynamic node does allow me to connect the Heart widget to it but evidently “2D textures” are incompatible with “2D dynamic textures”, so I guess that’s not an option.
I tried creating materials with the two heart textures so that I can just use Set Brush from Material. However, I can’t figure out how to properly set them up, as right now the heart materials just appear as black squares.