# It is better to loop an event with a delay or use the event tick?

**URL:** <https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [August 10, 2023, 9:36am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623 "2023-08-10T09:36:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 9:36am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/1 "2023-08-10T09:36:13Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/8/8/e8818cb4b5883ed9c8ded708b84e68480ab83fa3.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/e/5/8e5dc8ab3343505af03e38782c6183b0899362f6.png)  
Hello everybody!

I am currently working on a train system, and I have a question.  
Since I have to loop the event that keeps the train moving, I have currently found 2 approaches, but non of them seem correct to me.  
The first one consists in using the even tick, and the second one of using a delay to keep looping the event.

Both of them work, but I don’t really know which one is the most efficient.  
Any suggestions?  
Also, in case you know alternative ways to do this I am open to changing my approach, thanks in advance! 🙂

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 9:50am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/2 "2023-08-10T09:50:57Z")

</div>

> [@SpaceAce\_717](#):
>
> Both of them work, but I don’t really know which one is the most efficient.

Delay.

* * *

You did not ask but there’s a 3rd option → consider a Timer:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/7/1/87162501d9c2fb22e96fc5d12bd74ed71e836927.png)

It’s like a Delay but you get extra features.

---

<div class="post-metadata">

**Author:** ![gardian206](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gardian206](https://forums.unrealengine.com/u/gardian206)\
**Post date:** [August 10, 2023, 9:53am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/3 "2023-08-10T09:53:37Z")

</div>

the engine is already set up to do Ticks() both have advantages and drawbacks

benefits  
Tick: you get a lockstep to the “frame” where you know where in the frame step your code will execute, so everything in the Pre-Physics-Tick-Group will finish before the Physics step is triggered.  
Delay: your code will fire with a known minimal interval regardless of the Frame step and mostly consistently, so physics might have just finished, but the timer hit so your code is getting called.

drawbacks  
Tick: to many things happening in the same Tick-Group will result in hitching (players will notice frame delays especially if it is inconsistent  
Delay: similar to the benefit you don’t have the known location in the frame-step for where your code is running, so if your position update is run after the physics step now your actor/pawn/character might be inside a wall or another character and physics will need to adjust on the next step.

middling things  
Tick: many people will tell the evils of Tick, but this is usually the same people that don’t realize you can put a time step on Tick to get very close to those Delay-Loop timers.  
you can move things into different steps, so you can do some position logic on the AI to avoid it ever going into the wall to begin with so you can put it after the physics.  
Delay: each one needs to be set up and managed independently, turning them on/off, and even modifying the time step.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 9:55am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/4 "2023-08-10T09:55:52Z")

</div>

I thought your delay was 0.8. You run it 0.08 - as if it was Tick. Then Tick is better, simpler but you need to account for frame-time.

To be honest. If you need something moving properly, use a timeline. Especially if something is time sensitive and needs to last X seconds.

> keeps the train moving

Perhaps you could elaborate a bit on how the movement is supposed to work. Knowing trains and their fondness of tracks, I assume it’s moving along a spline? A `Timeline` _could_ work really well here. A lot depends on the method chosen for the movement, ofc.

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 9:57am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/5 "2023-08-10T09:57:57Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/c/40c8e29ad32ce55ae4990fd41babf1111ed0f907.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/c/1ac55d42d33b8695d9da16c08495f38a2fd7a619.png)

Thanks guys!!  
I am actually using a timeline, here is the full code that makes my train move.

Do you think using a timer would be better?

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 10:00am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/6 "2023-08-10T10:00:45Z")

</div>

And yes, it is moving along a spline!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 10:01am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/7 "2023-08-10T10:01:29Z")

</div>

You’re using the timeline to increase the speed, but not _move_ the train, right? You could have another timeline that is looping:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/d/8/8d839cc0282c8fb20a011f9cfe0612f16df7684a.png)

And use the Update to move the train, it triggers every frame.

* * *

Tick would be fine but I’d avoid combining these:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/1/1/c11df3214d9327ae3ddd5bafdd0d76531dc700a8.png)

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 10:05am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/8 "2023-08-10T10:05:45Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/f/3/7f30445dc8c4582e6f66a0a61c6ecdc583f4923b.png)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/9/b5915f021b0bf6db3e24387b9a827454c398f336.png)

That’s correct. The movement happens due to this distance check based on the spline’s lenght. Then the “Move” function will be fired and the distance updated.

Thanks a lot @Everynone I’ll try the looping timeline, if not working I’ll just use the tick. Thanks! 😃

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 10:07am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/9 "2023-08-10T10:07:56Z")

</div>

An example, just in case:

> [@Move multiple actors along spline](https://forums.unrealengine.com/t/move-multiple-actors-along-spline/437200/7):
>
> Here’s a simplified (compared to yours) script I’d use were I to push numerous actors along a spline: [[Image from Gyazo]](https://gyazo.com/cc07a1a805a8c28391c561dbac6e5380) Essentially, each car stores an offset. We animate another spline offset using a timeline, add both, and reposition the car. An optional Modulo wraps the value so we get perpetual motion.

This moves many separate objects simultaneously. Could be handy if the train has cars.

* * *

But it should work fine with Tick if that’s what you’ve got.

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 10:11am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/10 "2023-08-10T10:11:22Z")

</div>

At the moment it has only one cart because I was thinking about a system similar to mine’s monorail, but implementing more carts in a procedural system might be actually pretty cool.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 10:22am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/11 "2023-08-10T10:22:17Z")

</div>

I’ll drop a couple of related links, explore at your leisure:

- ticking spline train with controllable speed:

> [@Making platform move with spline but without timeline](https://forums.unrealengine.com/t/making-platform-move-with-spline-but-without-timeline/1167814/2):
>
> My initial gut feelings tells me you do not want physics here, it does not mesh with spline movement method well. However, you also say: making movement for a flying boat So… maybe you do. Could you clarify that physics sim is, indeed, needed and climbing / diving should affect velocity in a realistic way with no player input, bar setting desired traverse speed. set it to move forward by itself on a set speed instead of time? I also need to add a button/lever that makes the boat stop/move…

- takes advantage of spline slope & physics:

> [@Make a Ground Rail with Spline](https://forums.unrealengine.com/t/make-a-ground-rail-with-spline/789343/2):
>
> On the most fundamental level: check the inclination of the spline with dot product accumulate this value - that’s the speed use speed to progress through a spline You’ll need to add friction as this preserves energy as perfectly as frame time allows it. And input. And a gazillion other things that makes it a game. innocent

Good luck!

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 10:23am UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/12 "2023-08-10T10:23:14Z")

</div>

Thanks a lot @Everynone this is extremely helpful!

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 12:25pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/13 "2023-08-10T12:25:12Z")

</div>

Just a quick update on this. I wasn’t really able to use the looping timeline. Probably I just didn’t understand what you meant here.

However, I marked this as the solution since the tick works fine and I am going to use it 🙂

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 12:32pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/14 "2023-08-10T12:32:57Z")

</div>

> [@SpaceAce\_717](#):
>
> what you meant here.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/c/c/0cc4b766074fd6d0e08c72bc556f2e5e82e4728e.png)

These two nodes ☝ are enough to have an actor moving. To follow a spline, you’d:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/6/4/8645d04429562c387dee93a6aae8414bbda05e2d.png)

Again, this is completely optional and just one of the methods. Choose the best working tool for job. Seems you got that going already.

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 12:45pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/15 "2023-08-10T12:45:35Z")

</div>

Thanks man! The cool thing about game design is that you can always learn from more experienced people, just like I am doing right now 🙂

I think I am still going to use the tick, but you triggered my curiosity now!

So, this is the function that I am using to move the cart along the spline:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/5/d/e5d82d3c39c93edfb79a731589c4c47e96604603.png)

What I do not understand is where I am supposed to place that timeline.  
Here is the tick which handles the movement:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/6/a66933dd39c5c1092b2038fbadc663f589d55b8f.png)  
If I change this to a normal event, should I just place that after the second branch?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 1:19pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/16 "2023-08-10T13:19:31Z")

</div>

> [@SpaceAce\_717](#):
>
> where I am supposed to place that timeline.

Start it with Begin Play, or a Custom Event or do not connect it to anything at all since it can be auto-started:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/0/9/909c5f67d6ce06b043563680aefb42fca22cf213.png)

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/b/19b0bf6639acf1b0358348e1d212423d6be15a60.png)

If Speed is null, we don’t move. Essentially, the TL acts here as a flexible source of Updates.

* * *

A timeline is a component that can be controlled like so:

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/b/c0b7834ad746144b5d628ecbec0973f52c221666.png)

* * *

Again, the crux is in the details - really depends on what the big picture plans are for the train. It could work.

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 1:23pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/17 "2023-08-10T13:23:59Z")

</div>

This is really amazing man!! Thank you so much!!!

I’ll give it a try as soon as I can, just a last question since you are clearly more expert than me: performance-wise, do you think this approach is better than the tick?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 10, 2023, 1:34pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/18 "2023-08-10T13:34:38Z")

</div>

Probably unmeasurable and utterly negligible unless you have a 1000+ trains or are making a legacy-compatible mobile product. In which case you’d probably opt for a time manager actor running timers and dispatching updates at specific intervals to a bunch of non-ticking actors who can interpret that.

And you’d not be using blueprints for heavy lifting.

* * *

This:

> [@gardian206](#):
>
> Tick: many people will tell the evils of Tick, but this is usually the same people that don’t realize you can put a time step on Tick to get very close to those Delay-Loop timers.  
> you can move things into different steps[…]

Tick is demonised because people put stuff in there that does not belong. If you want to see an update every frame… that’s what tick is for.

* * *

> do you think this approach is better than the tick

- spawn 1000 actors with a timeline updating script
- spawn 1000 actors ticking the same script instead

See how it goes. 🤷

If you’re making 1 train, it does not matter. Choose what is more convenient to work with / understand.

 ![BPs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/b/60b0eb6007c21a61ea2313e3ec6800e9a1663fd5.jpeg)

One way or another, it’s gonna be like this ;p

---

<div class="post-metadata">

**Author:** ![SpaceAce\_717](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/spaceace_717/32/88713_2.png) [@SpaceAce\_717](https://forums.unrealengine.com/u/SpaceAce_717)\
**Post date:** [August 10, 2023, 1:38pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/19 "2023-08-10T13:38:04Z")

</div>

Crystal clear!

Thanks a lot man!!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 9, 2023, 1:38pm UTC](https://forums.unrealengine.com/t/it-is-better-to-loop-an-event-with-a-delay-or-use-the-event-tick/1256623/20 "2023-09-09T13:38:54Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
