UE4 Ticks, Timelines, and Timers
A comparison between these three and explaining their use cases
You shouldn’t use Ticks
I have read this sentence countless times. It is a widespread assumption so many developers simply accept it as true. But is it?
Let’s take a closer look at the Tick event and its alternatives.
It’s time to do the Tick it’s justice.
The Tick
First, let’s clear up what the Tick is, and what it does.
The Tick event is executed on regular intervals-usually once per frame, in an actor or component.
You can change the Tick interval with the
Tick Interval (secs)
option under Actor Tick.
Ticks are assigned to a Tick Group. Which determines when during the frame the actor/component ticks.
The Tick Group defaults to PrePhysics, which is fine in cases where the actor should interact with physical objects. This way, the actor’s logic is completed when the physic calculation starts.
Some actors might need a different group, depending on their use case. But I wouldn’t waste too much time on this. PrePhysics is fine in the majority of cases. However, It is good to have this knowledge in mind.
Prerequisite
If you have an actor, which depends on the data of a different actor, you can use the Add Tick Prerequisite Actor function to ensure that this actor only ticks after the prerequisite Actor.
Ticks, Timers, and Timelines
The two alternatives to Ticks are Timelines and Timers. Here is an overview to know when to use what.
Avoid checking intervals
On a side note, using intervals to check the state of something can often be optimized using custom Events.
Here is an example:
Instead of checking every X-interval if the actor overlaps with the Sphere actor, we created a custom event which is called when the actors overlap.
What to do
The Tick event is not necessarily bad, but can often be replaced with a better alternative. Take a look at your ticks and ask yourself if you need to check the code every frame, all the time. If not, make use of timers, timelines, or custom events.
If there is a case when you need to tick every frame, do it. And don’t ever feel bad about it.
Optimization is a complex topic. If you experience performance problems in your game, replacing ticks with timers probably won’t help much.
This is all for today. Are you using ticks, or do you completely banned them from your toolbox?
Do you want to learn more about game development?
This might be interesting too:
Originally published at https://gameinspired.substack.com.