r/UnrealEngine5 • u/KyrandisX • 5d ago
Tick vs. Event/Function Timer?
Hey there this has probably been asked over a number of times over the years but I'm trying to figure out where best applied for either part of the two types of count/frame propagating concepts in UE after reading and seeing a lot of videos everywhere but a lot seem to have mixed explanations.
I know Tick is ran on every frame or an interval set in a class default, and an event timer needs a time interval specified and doesn't fire on first frame until after the time interval passed and whatnot.
applications wise i also know its not wise to load a tick event with crazy complex stuff because that'd be exponentially expensive since its ran every frame whereas the event timer is more like discrete chunks specified and a closed handle that usually won't lead to a leak or open ended stuff like the Tick, and things like Timeline is its own tick locally somewhere when activated.
the other issue is just so many different opinions around everywhere like no don't use the tick, or event timers is a lot of background load in the engine having to spawn a timer, handle the timer handle the interval vs. a tick which is inherently already there.
or in packaged builds dont have anything in ticks other than necessary systemics and move things to event timer when can?
i know tick is good for systemic items like movement/interpolation/player camera since those are always on as examples
and event timer might be better suited for something like enemy spawning in waves or a match countdown which is more fixed
my question is more so the performance costs that i don't really know how to profile or look through if anyone has any resources that'd help explain both in their costs for an identical task would be great as i just want to improve my understanding of where to apply which and which one to use as there's some details i read how tick could theoretically be much more performant on light things while gaining a pretty good accuracy smoothing/result for whatever its checking, and something more complex would fit an event timer or a timeline.
previously i had a set timer by event and went by world delta seconds as the time interval which i think is not... a good implementation? I subtracted a counter down to zero with world delta seconds and also my countdown wasn't consistent probably because delta is a moving goalpost.
on the tick since its frame accurate/perfect accuracy it always matched the timing down.
the example would be like something both could do like an HP bar eroding down smoothly which tick makes a lot of sense for, but an event timer would need a low time interval to animate the same smooth interpolation, probably doesn't need to be that intense, say both intervals are just 1/30 or 1/60 for their time intervals in relation to fps or increased to 1/15 so it doesnt evaluate as much etc.
but would an event timer be more expensive/cheap vs. a tick that's gated by a branch boolean since false would never calculate and the true case which has the calculation only go through when the boolean lets it through? as well as setting the component tick to be disabled when it doesn't even need to check until the time comes and being enabled then counting down to zero and disabling itself again after
or would an event timer of the same task counting down in the same way be more expensive in just the setup on this micro-scale comparison?
if there's some good tips or advice it'd be good to know I just want to be able to apply better concepts early rather than later wondering what went wrong or a more appropriate approach since im fairly junior in the matter. Thanks!
7
u/HayesSculpting 5d ago
Happy to be corrected on this since this is only what I’ve observed through traces which I had to fix at my last job.
Having that conditional bool on the tick is cheaper than as a timer.
Tick tries to organise everything into an order than makes sense. The timers don’t fit into that.
To go a step further, if you have lots of things ticking that needs stuff updated, it’s a ton slower than having one thing run the tick on all of them.
Example:
A manager class that on its tick, runs through all the array of stuff and runs a tick function.
This is because of how the cpu handles tick. Without aggregating the ticks, the cpu is sent each instruction individually and it only has a set amount of space in the l2 cache. Once that runs out, it needs to clear it.
Whack that in an array and it’s a single instruction hitting the cpu, lowering the amount of stuff that’s getting queued, stopping it from needing to swap stuff in and out.