Move multiple actors along spline

So for my project i need to spawn multiple actors along spline.
With i have managed to work only one of the actors rest of them are standing still.
Where am i wrong?

You’re getting just 1 element from the array - (Get 0). Do a ForEachLoop instead of Get. But you need to do it during Timeline’s update.

Also, you should execute GetAllActorsOfClass (if you must) from the Completed pin of the first loop - otherwise, it’s pure chaos.

Hey there, did you ever manage to solve this? I am facing a similar issue - my actors spawn along the spline but do not move.

Perhaps attach a screenshot showing your attempt and folks will be happy to poke holes in it.

Hey Everynone - good advice!

I am quite new to coding so no doubt there will be many a hole to be poked. Please see code attached - it seems to generate vehicles along the spline no problem, but they don’t move when I hit play.

Atm, you’re attempting to move the Multi Vehicle Generator actor along the spline. The child actor component cars are not attached to this actor as you flagged it as manual. That’s what I’ve gathered.

How is it supposed to work in the long run?

  • cars move independently on each spline and the distance between them can change?

or

  • the entire spline moves with all cars attached?

Here’s a simplified (compared to yours) script I’d use were I to push numerous actors along a spline:

Image from Gyazo

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.

3 Likes

Thanks for your reply, Everynone, it is much appreciated. In the long run, the idea was to have blueprint cars (blueprint code makes the wheels rotate) follow a spline with fixed spacing i.e. the distance between them can’t change - essentially what you have produced with the Cubes in the gif above.

Apologies for the following newbish questions, if they make any sense at all:

  1. Is this Blueprint script for your Spline referencing another Actor Blueprint, called ‘A Car’, which just has a static mesh component (a Cube) and stores the Car Offset float?
  2. I am a little confused as to how you connected the Array Element output from the For Each Loop to the Car Offset float (highlighted in image attached) - I get an error saying The static mesh actor object reference is not compatible…
  3. Do you need to connect the ADD Array to the Timeline (highlighted in my screenshot) or does the Timeline need something connected to the Play input?

Thanks a lot for this help, I’ve spent days trying to crack this!

Is this Blueprint script for your Spline referencing another Actor
Blueprint, called ‘A Car’, which just
has a static mesh component (a Cube)
and stores the Car Offset float?

  • the aCar is an actor with a Static Mesh Component and a Car Offset variable
  • the blueprint owning the Spline spawns a bunch of those actors and keeps their references in an array (it’s very similar to what you do, but instead of having a Child Actor Spawn a car, I spawn it directly)

I am a little confused as to how you connected the Array Element output
from the For Each Loop to the Car
Offset float (highlighted in image
attached) - I get an error saying The
static mesh actor object reference is
not compatible…

Each car actor has its own Static Mesh and a Car Offset variable (Instance Editable and Exposed on Spawn so the pin shows up when you attempt to spawn the actor - can be seen on Spawn Actor from Class node)

The array holds all the actors. The ForEach loop nodes iterates over the elements of that array. This way, as the Timeline updates, you get a chance to access every aCar, its components and variables, and update them if necessary.

Do you need to connect the ADD Array
to the Timeline (highlighted in my
screenshot) or does the Timeline need
something connected to the Play input?

Sadly, I see no screenshot attached. The Timeline can be set to Autoplay and / or Loop (note the extra icons on the node) or be triggered manually. Here, it’s automatic - there’s a panel above the track graph inside the timeline editor with a bunch of switches.

1 Like

Meant to say, thanks a mil for the help Everynone - your advice did the trick! :smiley:

Hello @Everynone

Cheers for sharing this! This is exactly what ive been looking for and found this after much searching in forums. A bit of a BP newbie here and I have managed to replicate your carGen BP shared above without any errors. But sadly when I play it, nothing moves and only one car (cube) is generated on point[0] of the spline. Please see attached, screenshots of my BPs, gameplay and timelines. Please if anyone can tell what I have done wrong here, would be much appreciated!
Thanks in advance!
:slight_smile:

Hello @Everynone and all

Cheers for sharing this! This is exactly what ive been looking for and found this after much searching in forums. A bit of a BP newbie here and I have managed to replicate your carGen BP shared above without any errors. But sadly when I play it, nothing moves and only one car (cube) is generated on point[0] of the spline. Please see attached, screenshots of my BPs, gameplay and timelines. Please if anyone can tell what I have done wrong here, would be much appreciated!
Thanks in advance!
:slight_smile:

What is your Cars variable set to?

Also, this should be modulo not division:

353699-screenshot-1.png

That’s probably it.