I have a healthbar that displays the health of my character, but I need to link text to the health variable so that the text displays my health out of 100. I also need to display it onscreen as I am having trouble with that.
This is my event graph - I’m not finished but I need the next step:
You have a couple of options. But first let me help you make the widget a bit more efficient. You are setting a reference to the character on the widgets construction. But in the get healthbar function you are getting the player character and casting again. You can save some time by just using the referenced variable you created when the widget starts (New Var 0).
So In the Get Text function, you could set it by getting the percentage you have now, and multiplying that by 100 and setting that as the text. Or you can pull the health variable from New Var 0. I recommend the second since you don’t have to do an unnecessary math function.
Now as for the aligning of the text. I’ll need to see your widget settings pane for it. Because I don’t know if it’s parented to the health bar, free floating or how it’s supposed to be aligning.
Beat me to it. This should lead you in the right path. My bet is that the health value itself is normalized (between 0 and 1) like in the example from this guide. If that’s the case multiplying by 100 is still necessary in both cases. I’d also recommend following it up with a truncate node as well, if you don’t want any decimal place. This will effectively turn the value into an integer between 0 and 100.
Okay thank you, both of these answers were really helpful. Some things i don’t really get (ive had ue4 for less than a month) but what you suggested solved my problem so thank you