FTimerManager Timers vs EventTick-based Timers

Hello

I’m making simple spawner that’s supposed to spawn actor every X seconds, and I’m wondering what are the advantages of using FTimerManager over simple

timeToNextSpawn-=DeltaTime;
if(timeToNextSpawn<0)
{
SpawnOneActor();
timeToNextSpawn=10;
}

in EventTick method.

But I guess I’ll do something like that more often, so let’s go further.

What about more complicated examples, like MMORPGs(or just RPGs) with lots of ongoing effects?
I know I can pause each Timer separately without having extra bool variables like “isStunned”(then his auto-attack cooldown should not got down) but looking at FTimerManager I can’t see anything that would allow me to manipulate timer(i.e. if character is buffed and his attack speed is doubled I would substract doubled DeltaTime in EventTick as long as it’s buffed).

So my question is: when to use each of them? Is it up to personal preference or is TimerManager better optimized and for performance sake it’s better to use this one?

If you need frame perfect timing (since tick is executed per frame) then use Tick, otherwise use Timer, i think in your case timer should be enouth

Timer handles are threaded iirc, and they are much cleaner (they keep your code free of unnecessary time tracking variables and checks). They can fire and forget and they can control their tick timer better. There is undoubtedly more overhead using TimerManager, but I strongly recommend sticking with it. If you need to worry about TimerManager’s performance you are doing something wrong. Don’t try to micro-optimize like that.

Don’t reinvent the wheel. Use TimerManager.

TimerManager use TArray to store timers. Everytime you use any timer function there is slow linear search from those list. More timers you use, slower TimerManager. I just profiled that TimerManager used ~10% of our frame time with ~1300timers. It’s super slow to use for everything.

1300 active timers is quite a lot. I don’t know the context but it is beyond a doubt that it is a place of optimization for you. If a cheap operation like timer management is using 10% of your frametime you are in serious need of redesign. That is not the engine’s fault - its yours.

@Kalle-H
Just to be clear, if you use any specific-per-timer function, like, get THIS timer rate, or Clear THIS timer, it does the search, because it is inevitable… Now just to roll timers, if you look at the implementation, it doesn’t do this search, so the quantity doesn’t affect performance then, it uses something like a stack, so it only needs to compare the current time with the closest-to-end timer. Every time you add a new timer, it goes into place to keep the right order, from closest to farthest to expiration, so it only checks the top one, off course with a while, so it will fire all expired timers on that frame.

1300 isnt a lot, considering how often they can be used - player management, AI, etc.

Hi everyone,
I’m quite new to UE4 and I am working on a project where I update a Pawn’s position according to data sent from an external program using TCP. I have modified 's tutorial to adapt it to UE4.18, and it is using timer functions to read data from a connected socket. says some of these can be thread, but I don’t really know what it means, and even less what would be the advantages of that. I really need to keep position updates synchronous with the incoming data, and I wanted to know if you had any advice on whether I should use TimerManager, Tick function, threads… I imagine that if I read data with TimerManager and update my Pawn’s position in the Tick function, there might be some problems.
I know it may not be 100% clear but I’m still looking for clarification myself. Any explanation (even if it’s not a full answer) is welcomed !
Thanks in advance :slight_smile: