Actor Health Regeneration based on Time Elapsed

Bottom Line Up Front: Which blueprint node(s) might allow me to dynamically change a float variable based on a time elapsed or a timer of some kind?

I’ve created an actor component that sets HP, registers taking damage, applies it, applies healing, and also has a regeneration function using the “Set Time by Function Name” node. It works as intended but I’d like to get a little more detailed with it.

I have two variables that the function and “Set Time by Function Name” node rely on to actually regenerate the actor’s HP; “HP_RegenRate” (float value for time in seconds) and “HP_RegenAmount” (float value for HP). What I’d like to do is begin tracking when the regeneration begins, perhaps using the “Get Game Time in Seconds” node, and gradually increase the potency of one of my variables as time goes on.

For example, if the starting/default values of “HP_RegenAmount” and “HP_RegenRate” are both 1 (i.e. 1 HP regenerated on every 1 second ), I would want to calculate and set an increased “HP_RegenAmount” float of 2 on every 1 second after the actor has been regenerating HP for 5 seconds. And then an increased “HP_RegenAmount” float of 4 on every 1 second after the actor has been regenerating HP for 10 seconds, and so on.

After some tinkering, I made this change to my blueprint and it works, but I can’t help but feel there is a more elegant method. Something that provides a smooth, gradual increase, not hard increases at time-elapsed = 3 seconds and 6 seconds. I arbitrarily selected 3 and 6 seconds for testing purposes.

I changed my HP_RegenAmount variable to HP_RegenAmountDynamic, added variables HP_RegenAmount01, HP_RegenAmount02, and HP_RegenAmount03 to store the hard coded tiers of HP regeneration (1, 3, 9 float values respectively). Added two delays after the HP regeneration function begins at the “Set Timer…” node to act as triggers for when to set the new HP_RegenAmaountDynamic float to HP_RegenAmount02 and 03 respectively.

image

I also needed to add another Set node to reset HP_RegenAmountDynamic to HP_RegenAmount01 after taking damage, and I had to tweak the Regen function to ensure HP_RegenAmountDynamic reset to HP_RegenAmount01 once the actor’s HP value reached the max value.

Depending on your needs it could be appropriate to set up a timeline so you can use a ramp up healing curve :

Awesome, thank you, that’s exactly what I was trying to do!