How would I set up a timer so my player's magic value will naturally return to 100?

This is my magic system for the player, as you can see, having too little or too much will start to harm the player’s health, and naturally, I want it to slowly regenerate back to 100, whether it be too high or too low, but I am unsure how precisely do to that.

Sorry you wanted a timer derf :melting_face:

If you have tick event add this to it if not add a tick event

I mean, tick or timer, as long as it works.
Edit: Seems custom events don’t work within functions…

If you are going to use tick, make it event driven. What I mean by that is turn tick off when magic is at max and only turn it on when magic has been used and needs recharging.

Also I suggest to not use a delay node with tick and just do → PlayerMagic = PlayerMagic + RechargeRate * DeltaSeconds.

1 Like

Ok, so how would I do that?

You would have to do the controlling the tick event elsewhere you could check for max and turn tick off here but turning it on and off in your use case might be hard

True, I wish there was just a simple “When A: start timer, when B: stop timer” thing, which would send out either a boolean, integer, or float at a set rate.

This is a quick example of how it could work. This was all done in an actor component:

  • How I trigger it:

    The idea is that this would be connected with the spell struct / component or how ever you are planing to configure them.

  • CE_ConsumeMagic is an event that gets called when the player wants to execute a spell. This event checks if there is enough magic to execute it. If there is enough, subtract and run another event that will turn on tick.

  • CE_UpdateMagic checks if there is magic to recharge (might be redundant) and sets the variables accordingly. bIsRecharding bool is here just in case something else wants to know if magic is recharding, doesn’t really do much.

  • In tick first we do MagicCurrent + MagicRechargeRate * DeltaSeconds, this will add X amount of magic per second capped at MagicMax. the branch checks if MagicCurrent >= MagicMax: if it is, turns tick off and bIsRecharging false, else keep recharding.


Doing it in an actor component lets you have a separate tick from the character…

In case I added stuff that you don’t need, just skim it.

Fascinating, I only just started using UE4 so a lot of this stuff is quite alien to me, but I’ll figure it out, it seems to work good. I’m mostly just hammering code together by intuiting what everything does from their names, as well as the occasional youtube tutorial, so.