# Can timelines/interps be used in a loop? 4.26

Hi, I’m testing out a snake based system where a tail of actors follow a pawn. It’s working with the code below but I wanted to add a timeline to smooth/delay each actor when it catches up to the next position.

As soon as I add a timeline/interp it just does not work anymore. What am I missing?

Capture below interp speed is at 0, which allows it to work (no interp) but as soon as I change it it stops moving. Thanks for any help!

Yes, but do it the other way around. Timeline with a loop on the update pin. Use two arrays, one of starting points, the other is target points.

With interp, if you want to do more than one point, you need an array of targets to work with.

Thanks for the help! So set up the timeline like below?

But the vectors would both have to be in arrays? I’m guessing I’d have to do a loop in a loop to cycle through each of those vectors then? Sorry still a noob!

With a timeline, you have to set the start and end points BEFORE going into the TL.

If you have multiple objects, that means setting multiple start and end point, ie, two arrays.

Use this

as the index into those arrays.

I can give you an example later:slight_smile: if you can’t get it working

1 Like

What if each segment only cared about where the previous segment was:

Here, there are no arrays or looping. The 1st segment is chasing the head. 2nd one is chasing the 1st and so on…

If the tail pieces need to follow the path taken by the head precisely, I’d opt for a spline instead.

1 Like

Sorry for the late reply, I don’t fully understand how to get two separate arrays into the timeline… sorry for being so dumb! Won’t the array index just be giving me the index number of the current element?

And your snake is amazing haha. I am trying to do it all as a grid based system, so right now each grid is a 100*100 square and am using the same size square as the pawn to make that more obvious.

How would you like to handle the tail? Each piece is an actor/pawn or just a basic static mesh? Judging by what’s above, you’re using actors - give each actor a timeline and feed it next location it needs to move to.

You can absolutely do it with a single timeline but it turns fiddly with arrays and all. Especially when you start adding more stuff later on. Things will get dense in the head - the segments could take care of some of the logic.

Yeah currently an actor with that cube in it and the rest is done on the pawn/head. Need an actor ( I think? ) because eventually I want them to be creatures with anim on.

So are you saying I need to call a timeline from within the tail blueprint?

Ah, it’s going to be that kind of snek.

I can post a more detailed setup for the above (on Monday perhaps). If you prefer to give this a crack yourself, here’s what I did:

• the head spawns the tails and keeps them in an array
• each tail has a timeline
• when the head moves, it loops through the tails and feeds them target location to move to and a delay value indicating when they should start playing the timeline

Admittedly, there may be half a dozen other ways to handle all this.

Great thanks! Makes sense reading it… will have a go at it!

Ok well i made some progress, I got one tail to use the timeline but then they all stack up on each other after the first one. I think my brain has melted at this point, was it at least going in the right direction?

Move tail is in the tail actor blueprint and Update Tail is in the pawn.

Came back to try this, the timeline works on the whole tail, but I just cannot figure out where to put a delay to offset each tail segment. It currently moves up as one whole piece at the same time. Any ideas?

The example with the ‘stepping tail’ came from @Everynone

figure out where to put a delay to offset each tail segment.

You’d want to multiply it by the index of the tail. The tails that are further from the head sit further in the array, their indexes are higher, resulting in longer delays.

Here’s what I did in the example above:

## Snake Tail Segment

The custom event pipes in the `End` location for the timeline and a `Delay` value telling it when to start it.

Ignore the crude input handling.

The one thing that absolutely needs improving here is when to allow for another head movement - we need to wait for all the tail pieces to complete their moves (unless you have another plan for this, of course!).

I see 2 options here:

• math it out - we know how many pieces there are and their delays, can be added together and the head must wait that long
• or, dispatch the last piece’s timeline’s Finish event, the Head will then know when the last tail finished moving
1 Like

This is fantastic thanks for taking the time! Its useful seeing other peoples code as I definitely forget to use some things.

I must ask, is using a timeline/this method the best solution to this problem? Are there any easier ways you can think of? I really didn’t expect it to be that much work and as you said the longer the tail gets, the longer the delay. Because it will interrupt the timeline if the head moves before its complete, right?

In my head I should just be able to create a float curve, put it in the alpha of a lerp with two locations and when its fired off it does that move. But that doesn’t seem possible without a timeline.

didn’t expect it to be that much work

Famous Last Words!

I must ask, is using a timeline/this method the best solution to this problem?

I think this will depend on what other features are needed further down the line.

The Timeline will give you plenty of control but, at the same time, it will make the whole thing somewhat rigid. With a TL, those pieces must stick to the rules of the movement.

Were you to use `vInterpTo` instead, it would be easier to script a more organic behaviour but that would be more difficult to control. Hard to advise, never made anything like that before but it does sound like a great exercise!

Because it will interrupt the timeline if the head moves before its complete, right?

Yeah - precisely, if the head moves prematurely - before the other pieces have finished moving, the current setup breaks. We either need to put a condition for the head move or approach the tail catching up differently - allow many head movements while the tail catches up more independently.

How should it work? The head moves as fast as it wants and the rest tries to catch up as fast as well?

One way or another, it will require at least a moderate amount of tinkering.

testing out a snake based system

Another method you could consider employing is a spline. As the head moves it drops spline points. This would sure come with advantages and disadvantages as well.

1 Like

Thanks for all the info really appreciate it! Definitely a lot to experiment with still, Nokia made it look easy!