I’ve been following a tutorial on how to make a health system which uses integers, and came pretty far in it. I have health, can simulate damage, and have setup a health pickup. In trying to create a regen system though, I’ve found that I seemingly need to use floats, particularly when it comes to delta seconds and world time. I’m not sure how to proceed as I can’t seem to find a health regen guide that doesn’t use floats. Are floats supposed to be used for this sort of system, and is it possible to convert the existing setup without issues?
You dont have to use float at all.
Floats give a bit more flexibility in every kind of calculation but it depends on what you want to achieve.
Do you need the regeneration to be as precise as possible? ( = every frame) or just some health after a while?
Single or multiplayer based?
I love to use Timers for regeneration and for that you could also use integers.
You can create a system to repeatedly call a function to increase your health.
Create a function, I’d call it StartRegen;
Create a boolean bIsRegenerating?;
Inside your StartRegen function, make a branch to check if you bIsRegenerating is true. After that, increase your health by ‘1’. And after that, use the node “Set Timer by Function Name”. The Function Name will be StartRegen and the time you decide.
Following this logic, you can get close to an analog health regeneration (using int) depending on the time you set inside Set Timer by Function Name. It’s a good way to control how much health you want the player to regen in a period of time. It has, too, condition to stop regenerating since you set the bIsRegenerating to false, it will not execute the loop again. You can add that it stops regenerating when the health is set to maximum value and it interrupts the call loop, too…
Floats are nice to have and use, but are not required for an operating health system. Depending on the type of regen system you have in mind, your mileage may vary.
I personally put the regen system into a Function. I put all of the handling of the regeneration into the function, including the checks and balances of whether we have exceeded or even if we can regenerate. All of this is figured out before any regeneration is even done. I will leave it up to you on how you wish to accomplish this, and if you are following tutorials, it is really easy to adapt the system to Integers.
When setting up all of the stats and stuff, put a Set Timer by Function and put the function name in. Turn on the Looping and give it a delay as you see fit, I personally use a variable so that it is unique to that instance of the blueprint. The nifty thing about that variable I just made, it is a Float variable. This is where you can implement the Float part of the tutorial if you deem it necessary.
Singleplayer for the moment, but possibly multi in the future. I’m trying to setup a system that regenerates health say 5 seconds after you’ve last taken damage. I was able to get the regeneration to work, but the delay value seems to repeat. (i.e. 5 seconds, +5 health, 5 seconds + 5 health). I tried the retriggerable but that doesn’t seem to work at all.
I tried doing this, but I couldn’t seem to get it to work. I should probably note I’m very new to blueprints.
I’ll give that a try. This stuff gets confusing pretty fast. I’m surprised there isn’t a whole lot of coverage on how to setup extensive health systems (health, shields, regen, etc.).
There are a LOT of tutorials on setting up a health system. UE4 even comes with a version of it, themselves (don’t recommend it at the moment). Your best bet would be to take a look at some of the YouTube Health Tutorials for UE4 and see what they do. I wish I could show you my setup right now, but this laptop seriously lacks power.
I’ve found many that have to deal with health systems yes, but I don’t really see any covering the topic of regen. Those that do don’t very well. I’m trying to get my health system which uses integers to regen after x time since taking damage.
You may want to consider some Sprint tutorials. They cover the exact concepts you are thinking of doing with health, except having to do with sprinting. Same concept, just a different condition to change.
That’s a good idea, I’ll check that out.
Here is what I created based off of your post. Not sure if this is what you meant, but it doesn’t seem to be doing anything. My HP regenerates as soon as it is taken away. I also managed to convert all of the integers to floats.
Try something like in this picture:
Here you can see the variable IntervaltoRegen. That variable will be important for you to set the regen rate. If you set this variable to 0.2, in 1 second, it will run the function 5 times, so it means your character will recover 5 health points. You can decrease the time to increase regen rate.
Let me know if this solution works for you
I gave your setup a go. It pretty much functioned like my other regen setups, except it exceeded max health. Clamping it, or using a modified setup like below fixed it but the regen rate is still immediate. I want it to have a delay before regenerating. The rate of regeneration in the setup is great, I want the quick regen, but I want it to happen x seconds after taking damage, that way the damage isn’t constantly fighting a constant regen. Here’s what I did based on your image:
Also, this is the tutorial I used to setup my health system if that may give you an idea of how it works.
I appreciate your help!
I see. So after your character take damage (that should be on the Damage event), use the same Call function by Name, fill with your Health Regen function name and the Time will be the delay you want it to activate. This will be a delayed start for your Regen Loop.
To immediately stop the regen after you take damage, set the boolean IsRegenerating to false. When you call the health regen, it will make the rest for you.
You are welcome, hope this can work for you.
After taking a look at the tutorial, if you’ve created the Damage Player function, you should put that setup I said last post inside this class.
After the Take Damage node, set the boolean IsRegenerating to false and call the Set Timer by function name here.
Take Damage -> Set bIsRegenerating = false -> Set Timer by Function Name = Name: Health Regen , Time: Delay to start regen
That might for you
It doesn’t seem to be working. I don’t know if I may be doing this wrong though. The Damage Player function is in a library, while the regen function is in the character blueprint. Is this the right way to do it, or should I be doing everything in the library? The reason I ask is because the bIsRegenerating is in the third person blueprint, but not the function library. Making a replica doesn’t seem to be doing anything.
Here is the damage player function, which is in the player function library:
And here is the health regen function in the character blueprint:
Got it, so you must get, inside the player library, the result of the cast to Third Person Character and pin it to the Object, in the Set Timer By Function Name. That means you are going to call the Health Function from inside the Object reference you are setting, in this case the ThirdPersonCharacter
Another detail I forgot to mention:
Get the same resultant node from the casting character and set its own boolean. Grab the blue pin, unclick in an empty space to open the context menu and type: set is regenerating. Set to false. Thus, you are going to set the reference inside the player, not the boolean inside the playerlib.
Ok thanks I’ll try this. Am I plugging this new boolean into the old spot in the playerlib?
Ok so I tried both ways, with the old one and the new boolean in that place but still the same result, regen keeps starting immediately after damage is inflicted. =/
edit 3: It seems to be working, what bugged it out was having an event tick call the function in the third person blueprint while I was calling it in the player library. I think it’s working now, thanks a lot for your help Gbr! =)
Seems I spoke too soon. This is accomplishing the same result as the delay, which is making the regen wait the time before it applies another + health. Essentially 5 second, + health, 5 second, + health.
Ok playing around with it, looks like it was due to the way I was adding the health. The timer was looping because the amount was too low, setting it to add max health - health has fixed it. After taking damage and waiting the allotted time, the health will regen to full. =)
Nice! Hope this solution fits your needs. Good luck on the rest of your project