How can I fix my traffic system?

So I have been making a basic traffic system for a very long straight road. I made it so as the player moves along it, vehicles will randomly spawn in the 4 lanes you drive down. The system is set up with a series of trigger boxes that will move the spawner a set distance ahead of the player so it looks like you are approaching them similar to real vehicles.

The spawner works properly, all vehicles will appear in one of the lanes. The problem is, at a certain point on the 100th trigger, it stops. This trigger doesn’t move the spawner to the next point, it just disappears from view and running over any subsequent triggers fails to bring it back. I don’t know why, in the level blueprint it all looks normal so I can’t see the reason for it not working.

Although, if I fail to fix it, is there a better system for moving the spawner ahead of the player car? I know I can attach it to the car but then it moves the spawner side to side with the car swerves and the traffic spawns all over the place then.

Edit

I am using Unreal Engine 4.27.2

hi,
if your road is straight why not moving the trigger in the direction a certain amount ? otherwise if it has curves you could make a spline and move it along that path.

get player position for that axis + amount ahead you like (which you could recycle if you trigger and before running spawn code,… save player position)

you could have 1 trigger instead of many and just run the spawn code and make a new function which moves it ahead. for security reasons you could disable collisions while moving and if in place reset it to trigger again.

cheers :slight_smile:

Hey,

I’m not entirely sure I understood everything you said. But, I did change the system to a way I think you were getting it. The spawner is ahead of the player and moves with interpolation now, and it’s speed/duration is set to a value that always keeps it in front.

This works! For a limited time. As I go down the road, the traffic spawning in the way I want but when I get a certain distance through everything disappears.

O.K. so my road is set up in segments. You drive down a tunnel and depending on what side of the tunnel you go down it will bring up a different piece of scenery. Bit like multiple choice. This all works until the final piece of scenery but for some reason, halfway down the second tunnel the spawner disappears and so do the traffic cars. I don’t, I can keep driving down a traffic less road. I think now that when I had the spawner be pushed by triggers, it would disappear when it should have been moved to that point and beyond, and it still goes away upon travelling there by itself.

There is nothing in that tunnel, no triggers or barriers that would make anything move unusually. It happens no matter which route I take, at that distance both the spawner and vehicles disappear.

hi,
this sounds pretty fun, like OutRun :slight_smile:
hmm could it be that the spawner get´s destroyed from some code or it has a limitation in range?
you could place a Destroyed Node with a print to check if this is the case or every time it changes its location do a print of the current Vector.

do your vehicles get removed all in the same frame or none spawning any more ?

cheers :vulcan_salute:

A bit like OutRun yeah, I like those types of games where you go from one place to another.

I can’t see anything that would cause the spawner to be destroyed. Nothing in the map, nor anything on the blueprint. The only code it has is to move from point A to pint B and drop vehicles periodically as it moves. I ditched the triggers to teleport it along, got a bit much in the level blueprint but your first reply gave me the idea to use interpolation points. I should have thought of that earlier as that’s what the cars use to move…oh well, that might change when I’m looking for more dynamic traffic.

But I did put the print message on it that tells me it has been destroyed and when it reaches that point, sure enough the message is printed. Glad to know that much now, I know it isn’t moving elsewhere or going invisible. Thanks!

As for the cars I destroy them with a block attached the car sitting at a certain distance from it and eventually the cars that you overtake get caught by it and get destroyed. So I did what I did with the spawner and put a car destroyed message upon being destroyed. I temporarily disabled the block that usually kills them as I don’t want a million “car destroyed” messages showing up. Well, they too when they reach that same point in the same tunnel, also get destroyed. So something must be causing that to happen but I don’t know what. I haven’t put any lifespans on either of them and the cars should only be getting destroyed from the barrier I have behind the player car.

I forgot to add, the cars that the spawner drops will remain in the level even when the spawner itself gets destroyed. The cars however, will also eventually get destroyed when they reach the same point the spawner did.

Edit

On the spawner, on its blueprint. If I untick “check if still in world” then the spawner won’t be destroyed when it reaches that point in the tunnel. Although it will stop in it’s tracks now, but won’t be destroyed. So it can’t seem to get past that point, not sure what to do. I can’t see anything physical blocking it or see anything on ANY of those blueprints that would prevent it from moving on.