Spawning and moving two different static meshes along a spline

Hi guys,
I´m currently working on a project.

The goal is having

  • spawn cars at start
  • 2 different cars run along a spline
  • with a defined offset in groups of 5 (so 5 cars of one model, 5 cars of another model, repeat)

With my method I´m able to add the first model. I just started out with working in Unreal and Blueprints so I´m kinda confused how the loops work.

I tried to insert a loop before my AddStaticMeshComponent but then it appeared that instantly 10 models are spawned in the same place. I tried to add kind of some logic using modulo and calculation, which didnt really work out for me.

Right now it would be great if could spawn at least one of the car models in this defined offset.

Would be great if someone could help out :smiley:




variables

This code won’t ‘port’ well to multiple cars, because the timeline can only run for one car at a time. If a second car comes along, it will reset the timeline for the first car, and so on.

There are several ways around this:

  1. Put the car references and their current locations in an array. During the timeline, you need to loop over all the cars, and lerp their locations from the array.

or

  1. Make an actor blueprint that contains the timeline and code to move the car. When you put a car on the spline, spawn one of these actors and it can move the car for you.

or

  1. If you have N cars, just put N copies of this blueprint in the level, no problem…

Hi ClockworkOcean,
thx for the quick answer. I think I´m gonna go with the third option of putting N bps fpr n cars into my scene.

Maybe later on I´m gonna swap to option 1.

Now I have the problem that although I´m putting in a value for my OffsetTime, my 2nd car still spawns at the beginning of the spline.

Do I need to calculate this with a vector to delay it or can I simply use the function delay and multiply my duration with the index of the car?

Another idea I have, is to give my Lerp in bp2 an A which will be dependent of my index of car, so that my location, doesn´t begin at 0 of Alpha but at for example 0.05

The BP looks ok. Does it just spawn at the start, and then jump to the correct place?

Both Cars spawn at the first spline point, it doesn´t even jump to another location.

What I did now is kinda like this:

kinda works out but the cars “stack” at the last point and then when both cars arrived at the end, both cars pop up on their first position

I’m wondering if that ‘set offset time’ node actually works. Either that, or print your offset and check it’s set differently.

Actually it doesn´t do anything.

But I think I´m fine with my Lerp solution.

at the end of the spline, do you think I can set the index of the car to 0 by using a hitbox? Like that every car should spawn at the first spline point no?

Better to code so that the car uses the whole spline, with a delay :slight_smile:

Ok thx for the advise gonna try to realize it ^^

I’m just taking a look…

I think you just need a delay:

spline

Trouble with offsetting the mesh, is it occupies less of the spline.

Mate it´s working as it should. Thanks for your help ^^ <3

1 Like