Now I see. It’s the whole “execute the calculation again” issue.
If you get the current health, reduce it by 0.25, set Current health with that value, then check the value of Current health, it’s going to give you (health-0.25) which is correct.
But if you then print string the value of the clamp, it would once again reduce the value by 0.25 so it will display 0.25 less than what Current health actually is…
Okay, thank you. I reorganized that part of the graph so that I’m only using the clamp once.
It seems to work now.
So, I think that solves that issue. I’ve got others, though.
I made some health pickups a while ago and they used to behave fine, back when I was displaying the health via a progress bar (and my max health was a set value of 100). Now that I’ve changed things, though, the health pickups are wonky. I’ll take a tiny bit of damage, touch a health pickup, and instead of replenishing what was lost all of my hearts are wiped out, emptied. And if I’m at full health and I touch two pickups in a row, that also empties all my hearts.
No idea what any of that’s about. Rather than try to nail down the problem with my setup, can I ask how you would approach the task instead? How would you implement a health pickup system, considering how the repeating heart UI works?
Maybe you are already doing this, but the primary design choice for modifying current health would be to do it once, in one place only.
So it would be a function or event on the character or player controller that takes in the damage, modifies the current health and tells the widget to update.
Instead of say the trigger box modifying the current health directly, fall damage event modifying the current health directly. Now they would instead call that function on the character.
And since max health does not really matter for this setup, that should be pretty much all there is to it.
Something modifies health positively -> calls function -> increases current health -> widget is updated, increasing the hearts.
Something modifies health negatively -> calls function -> decrease current health -> widget is updated, removing hearts.
The only somewhat problematic thing about this may be having a heal delta, or a DoT, that ticks every frame, because then the widget has to update every frame and there’s a “lot” of casting going on. It probably doesn’t actually matter, but there are optimization that can be done to the current setup to make it more performant.
That is the way I’m doing it, yep.
So, I think I might know what’s going on. It doesn’t really make sense, though. Whenever a health pickup is touched by the player, it calls an event in one of the player’s graphs. The event works almost identically to the player’s Any Damage event, just in reverse. (It adds health instead of subtracting it.)
Every second health pickup I grab, my hearts (and health) drain to zero. I decided to print some strings, and it turns out that my Max Health is being set to zero. And as you can see, I have a clamp there that maxes out at the player’s Max Health… which means the player is getting their health set to 0 as well.
Is this happening because I’m only setting the player’s current health, and none of the other stats in the Game Instance? Does the engine assume I want to leave all of the others blank? If that’s the case, I’m not sure how to proceed.
Ah yes. It’s got nothing with the game instance. If you have a struct with 2+ members and set only 1 member, the other members will receive the default value that the struct has. So in this case 0. You’ll need to also set the max health to equal the max health.
It’s like a vector, that’s a struct with 3 floats. If you just set X, the Y and Z will be reset, if you want to save Y and Z while only modifying X, you need to set those too. X=X+1, Y=Y, Z=Z
For this reason, it is a good idea to keep data that often change and are not necessarily dependant on others to make them variables, rather than being part of a struct.
I had it that way originally, but I thought it would be cleaner if I kept things in a struct. Looks like I was wrong!
So, I went through and divided the stats from the struct into their own variables, and as far as I can tell, everything’s working great. Health pickups are good, health upgrades also seem to be working fine… yeah. Hopefully it all stays that way.
I really can’t thank you enough, @ste1nar. I bet this was a big pain for you, but it made my week.