How To Constantly Set Locations Of Multiple Instances Of An Actor In A Timeline

Hello there,
I’m trying to make an enemy spawner, where each enemy that spawns follows a Spline from the beginning to the end.

I’m using a Timeline here to control the movement of enemy characters. At first I used an Actor Blueprint as my Enemy but then I changed it to a Character Blueprint so that I make it AI.

So, I want my player character to press a button, and every time he presses it, one enemy spawns and follows the Spline.

Everything works perfectly when I only have one enemy spawned, but as soon as I spawn the second enemy, while the first one is still moving, the first enemy falls off the Spline and the second one works.

I want my code to constantly apply the Timeline to all instances of my Enemy character in the scene, and constantly update their locations. But it seems like my code can only do this for one instance at a time.

I tried recording every spawned enemy instance in an array, and then make a For Each Loop after the timeline for that Array, so that each instance spawned still gets the location update, but it still doesn’t work, and my existing character falls off the Spline as soon as a new one spawns.

What am i doing wrong? (I’m pretty noob with UE)
Here is my code (one last thing: the dispatcher calls upon my Projectiles to follow the first spawned enemy from their own location. Also, this code is running inside my player character.):
1:


2:

3:

1 Like

You can do it with arrays of enemies and enemy positions, but it’s soooo much easier to just code it in the enemy.

The problem with your code, is you are only using one spline position. You need a position for each actor, if you want to do it this way.

1 Like

Correct me if I’m wrong, but I guess you mean that I need to have one unique “Set Actor Location And Rotation” node for each instance, right?
That will surely solve my problem, but is it okay performance-wise to have tens of these nodes running simultaneously?

1 Like

I take it back. You basically need this code in each actor you want to move along the spline :slight_smile:

I think you probably can do it in one BP, but not with a timeline…

1 Like

Setting actor position and rotation is going to fight with character movement component.
If you’re using Character, you should use an AI behavior that walks along the path, rather than trying to get it to exactly the point in question.
If you need to update the position, you should instead subclass your enemy from Pawn (which can also have AI.)

Separately, you need to put the timeline inside the Pawn blueprint, not in your main character.
The main character should just spawn an instance of your Pawn at whatever the spaning point is, and the Pawn class then contains the timeline that moves it along.
(You could even put this behavior into a MovementComponent if you’re going to make this networked.)

2 Likes

To be honest I was trying to this with an Actor rather than a Character, as all I need is to move the enemies along the spline. That’s why I tried this method.
What makes me wonder is that can a single Timeline handle multiple instances?
Like I spawn “Instance A” and it starts moving. While “Instance A” is in the middle of the path, I spawn “Instance B”, and it should start the Spline from the beginning.
So, it’s like my Timeline needs to be at the beginning of its curve and somewhere in the middle of the curve simultaneously, which I think is not possible. So, Instance A and Instance B both return to the start and traverse along the path together.
I think as Clockwork said, it doesn’t seem to be possible with one Timeline.
I wonder what should I replace for Timeline to do this for multiple instances with efficiency.

Make the actor a BP, and put the code in there. Solved :slight_smile:

1 Like

A single Timeline instance can only output one value at a time.
A single Timeline class can handle one actor per instance.
This is why putting the Timeline in the enemy blueprint, rather than in the player, will work – you create one instance of the enemy blueprint (class) per enemy, and thus you get one instance of the Timeline (class) per enemy.

1 Like

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