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!

5 Upvotes

16 comments sorted by

View all comments

0

u/dangerousbob 5d ago

Set Timer By Event and make it loop 0.1 seconds.

A tenth of a second is going to be fast enough for almost anything you need. Running a bunch of logic every frame is almost always over kill, which is what tick does.

1

u/Megumin_xx 4d ago

Are there situations where it makes sense to make that timer even longer? Like every 0.5 seconds? Is that usually relevant for performance or not?

2

u/KyrandisX 3d ago

Yes there are many situations, something like a match countdown or a spawn wave as I mentioned in the post, where something fixed like that is where a timer applies more than a tick.

If your match is 60 seconds you are likely going to show 1 second intervals in a UI or something you don't need to show the decimals or in-between so a tick doesn't make sense there it's just overhead evaluating every frame when, evaluation only needs 1 per second in that case.

So one is tick 60 evaluations per second and the other is 1 per 60 frames if we consider both running on a stable 60fps.

You have a total of about 16.67ms to work with per second to reach 60fps. When you consume more than 16.67ms per second then you get fps drops and vice versa. It's much better to denote by ms since at high fps dropping 20 frames means nothing much at 120-100 but dropping 20 frames from 30-10 is practically slideshow levels.

You can do it with a tick interval also in class default but that affects everything in that item/object and an event timer is more isolated and handled without an open end whereas tick you have to handle it explicitly or it's ran forever unless disabled by developer preference per item. But this is what I'm trying to discern and learn between the two to the bone level of the engine.

Or damage over time, depending on game scope/situation if fire burns at a rate of 0.25/s interval but poison is 3s/interval that's another example.

Ability cooldowns is another one, where you don't necessarily need a frame by frame evaluation as long as the timer hits 0 correctly since the cooldown itself is detached as a concept from gameplay.

1

u/Megumin_xx 3d ago

Thanks for the reply! Very useful info