event tick in seconds / 10

Hey,

I am new to UE4 and have a question on how to best tick events every 10th of a second.

Basically i have 3 values, health, stamina, and mana. I want to update these variables every 10th of a second. Currently i am using a delay of 0.1 seconds after the “Event tick” and have the main part of my blueprint execute after that. However, to me, this does not seem to be the best way to do it. :slight_smile: Plus i dont know how often an “Event tick” fires per second. :confused::rolleyes:

Do you guys have any better approaches to this?

You can use a delay loop that triggers when your actor spawns. Personally though I use tick with delta seconds to ensure my energy recharge is constant even when frame rates change. Default tick rate is 0.036

1 Like

I’m not sure that’s a good idea. From my experience I know that using the Delay node in this case is a really bad idea as it halts some other processes going in the same event (if he wants to add them).

Easy one, use a repeating timer

Thanks for the answers!

Dedrick, that was my approach too. However as Keytotruth says, it halts the events following the delay, which i definitely dont want. :slight_smile:

I am not sure I understand how the framerate drop influences the delay. I always thought a set time would ensure a constant updating of my variables instead of reffering to a framerate, which might slightly change during gameplay. But i could easily adapt to using delta seconds instead of whole or seconds/10 .

Would it be a problem if i have a rather long trail of actions firing every 0.036 seconds? If so, whats the best practise here?

Edit: you were faster Dannington. :D. Could you explain this a bit more please?

Create a “Regenerate” function and fire it through Set Timer node, after Event Begin Play. In the node, just type in function name and set desired delay and check “Looping”.
More about timers HERE.

To demonstrate Dannington’s and Slavq’s suggestions… :slight_smile:

The Function Name value (MyRepeatingFunction in this case) should correspond to either a argumentless function in your blueprint or a custom event. In this case I’m stopping the timer after 5 seconds to demonstate how to stop after a fixed time. You can also just let it run as long as the actor is in play.

That should work, however, I don’t think it’s necessary to have the Clear Timer node, as the looping check already does that.

Also, DaveL88, this is still unoptimized for what you want. Why don’t you just update those values when needed instead of updating them all the time? Like, for example, only update health after damage has been dealth or stamina when you hold the running button. That’s way more optimized.

1 Like

NisshokuZK just demonstrated how to STOP the timer, so it does not loop anymore after calling Clear Timer :wink:
I guess that DaveL88 wants to, for example, regenerate health/mana/stamina/whatever - so it needs to be done every X seconds.

I added the ClearTimer to demonstrate how you can stop a timer that you started before, for example if you only want it to run for 5 seconds. A more flexible way to use SetTimer / ClearTimer, in the context of health regeneration, is to start the timer the moment damage is taken and let the repeating regen function stop the timer itself once health is full. You can even combine this with a delay after taking damage by:

On Damage: Stop current regen timer -> Delay -> Start new regen timer that calls On Regen
On Regen: Restore some health -> If health is full, stop current regen timer

Some notes about timers and delays:

  • One timer can be active on a function at a time, repeatedly setting the timer will overwrite existing timers on that function
  • Similarly for delays: repeated execution of the same Delay node will overwrite the previously pending Delay

Its best to see Delay nodes like this: when entering a Delay node, a new execution thread is created that waits and then executes the rest of the graph in time parallel to the current graph.

Oh, that makes a lot more sense. xD
Then yeah, that’s perfect.

I will try it out using the timer like keytotruth has demonstated.

What i am looking for is a steady health regeneration like in Dota2 for example. The timer + function approach seems perfect for that actually.

Thanks for the help guys!

Oh I don’t use a delay, that was just an example, I totally forgot about looping timers. What I was saying about tick and framerate is because the 2 go hand in hand. The lower your framerate, the less ticks per second you get in, and that is when things get wonky. The opposite is true as well, high fps means more ticks per second, this is where delta seconds comes in. Delta seconds ensure that no matter what your framerate is, the math involved in your per tick will remain constant. IIRC delta seconds are the difference between tick rate and frame rendering time, don’t quote me on that though. If I have a Rate per tick of energy I want to replenish, I times my rate and delta seconds together and add it to my energy.

I probably did a horrible job of explaining that but here are some reference pictures