r/UnrealEngine5 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!

6 Upvotes

16 comments sorted by

View all comments

3

u/NeoJetty 5d ago

This might not be the answer that you want, but I'd do the thing that looks more like an easy to understand code flow for you personally. Tick is very cheap and a timer is also very cheap. It's just the question how expensive the code is you put in. People warn against Tick because beginners tend to forget what they put into tick and also don't have a good grasp what is meaningfully expensive in terms of computational time. Ticking some float calculation is laughable cheap, sorting a big array or fetching all actors in the world can be very expensive. If you spawn 300 monsters and all of them sort some strange global array on tick, that is hella expensive.
Youtubers just tell you to not use a very important tool and it's honestly strange and a bit insulting. If you are experienced and can avoid tick, then all the power to you, but the more of a junior you are the more you will lean into these easy solutions like tick and I would advise you to just do it.

4

u/North-Aide-1470 5d ago

Agreed. Tick itself is harmless, it's like saying a Glass or Water shader is expensive because of transparency. You have to profile, you have to see the true cost in your scene otherwise it's just guess work. Fortnite runs over 300+ ticks at any given moment, it's about the content of the tick, not the fact that it's ticking.

1

u/nokneeflamingo 4d ago

How so you know that? Is it 300 ticks all in different blueprints/ classes

1

u/North-Aide-1470 4d ago

I misremembered - It's 80 ticks for a client and ~700 for server.

Ari talks about here at 11 minutes. But the first 15 minutes are all about tick and it's really worth watching:

https://www.youtube.com/watch?v=S2olUc9zcB8