Any City Generator · Documentation
Traffic and Road Rules
Traffic runs in Play, not in the editor level. One traffic manager drives cars along the lanes of every road network in the level: they keep to speed limits, follow each other, change lanes and merge, and stop, yield or wait for green at each junction by the rules it was built with. This article covers the manager, spawning, how cars drive, junction rules, vehicles, your own vehicle Blueprint, performance and the limits.
← All Any City Generator documentation1 · The traffic manager
One manager runs all traffic in the level
BP_AnyTrafficManager runs traffic on every road network in its level, including networks added later. Generate City spawns one at the world origin when the level has none. To add it by hand, drag it in from Place Actors > City.
▾ Start and stop
These are Blueprint functions on the manager. Vehicle Types, Simulation Settings and Seed are read once, when traffic initializes at BeginPlay. To change them during play, call Shutdown Traffic, Initialize Traffic and Start Traffic.
Keep one manager per level. A second manager would run its own, separate traffic on the same lanes, and neither would see the other's cars.
2 · Spawning
Where cars appear and how many
The manager keeps a target number of cars on the road: the smaller of Max Vehicles and Vehicles Per Kilometer times the kilometres of driving lane it can spawn on. These settings are under Spawning in the manager's Details panel.
▾ Spawning
Viewers are the local players' view points; on a dedicated server, the manager's own location. With Around Viewers, put a Player Start inside the city or switch to Whole Network. When traffic starts, the roads are filled toward the target in one go, so expect one longer frame. After that, every Spawn Interval (0.25 s) the manager removes far cars and adds up to 8 new ones.
Cars can appear in plain view. Spawning does not check what the camera sees, so a car can appear 50 m away on screen. Lowering Max Vehicles during play does not remove cars: those above the target are just not replaced.
3 · Driving
How cars drive
Each car follows the car ahead with a standard car-following model (the Intelligent Driver Model), tuned by its vehicle type. Cars react to each other, to stop lines and to the junction rules.
- Speed. A car aims for the lane's speed limit or its type's Max Speed Kmh, whichever is lower, times its own speed factor. It slows down early for sharper curves.
- Following. It keeps a Minimum Gap plus Time Headway of travel to the car ahead, speeds up at most at Max Acceleration and plans its braking with Comfortable Deceleration. Harder braking, up to Emergency Deceleration (9 m/s²), is kept for emergencies. Brake lights come on when it slows down harder than 1 m/s².
- Lane changes. Once a second, a car on a road checks whether the next lane lets it go faster, with a safe gap ahead and behind. Cars don't change lanes close to the end of the road, and never change lanes to reach a turn.
- Merges. Where two lanes join into one, the car nearer the merge goes first and the other follows it. A lane that ends along a road merges into its neighbour zipper style. At a highway, cars on the ramp wait for a gap in the mainline; the mainline never waits.
- Routes. At each junction a car picks its next lane at random: most often straight on, less often a curb-side turn, then a far-side turn, and rarely a U-turn.
▾ Simulation Settings
These are under Simulation > Simulation Settings on the manager, next to the junction timings used below. They are read when traffic initializes.
4 · Junction rules
Who goes first at a junction
Each junction's rules are fixed when its road network builds. A car asks for permission as it nears the stop line and never enters a junction without it: it waits at the line. The rule set is the junction node's Control, under Network > Layout in the road network's Details panel.
▾ Control
Signals cycle through green, yellow and all-red for the node's Signal Green Seconds (18 s), Signal Yellow Seconds (3 s) and Signal All Red Seconds (1.5 s). Each junction starts at a different point of its cycle, so neighbours are out of step, the same way every run. At highway interchanges the ramps yield and the mainline never waits.
Gridlock clears itself. At stop and priority junctions, a car that has waited 12 s (Deadlock Break Seconds) stops giving way to earlier arrivals and to waiting cars with priority, but still waits for cars in its path and for room after the junction. A car stuck for 60 s (Stuck Despawn Seconds) is removed, and spawning replaces it.
5 · Vehicles
Vehicle types and the six stock vehicles
The manager's Vehicles > Vehicle Types lists vehicle type data assets. Each new car picks a type by Spawn Weight, then one of that type's Vehicle Classes and one of its Body Colors at random.
▾ Vehicle type
The plugin ships six types, DA_Vehicle_*, each spawning the BP_AnyTraffic_* Blueprint of its name, and BP_AnyTrafficManager lists all six:
- Sedan: 450 × 185 cm, up to 150 km/h.
- Hatchback: 400 × 175 cm, 140 km/h.
- SUV: 480 × 195 cm, 140 km/h.
- Van: 520 × 200 cm, 130 km/h.
- Bus: 1200 × 255 cm, 90 km/h, Max Acceleration 1.2, Time Headway 1.8 s, Spawn Weight 0.3.
- Truck: 900 × 250 cm, 100 km/h, six wheels, Max Acceleration 1.0, Time Headway 1.8 s, Spawn Weight 0.4.
One size per type. Every Blueprint in a type's Vehicle Classes shares its footprint and driving, so list models of about the same size, and make another type for a different size. Vehicle types are read when traffic initializes.
6 · Your own vehicle
Making a vehicle Blueprint
A vehicle Blueprint is a child of Ax Traffic Vehicle with a body mesh and one wheel component per wheel. The simulation moves it; the actor never moves itself. The quickest start is to duplicate a BP_AnyTraffic_* and swap its meshes. From scratch:
- In the Content Browser, click Add > Blueprint Class, expand All Classes, pick Ax Traffic Vehicle and name it, for example BP_MyTaxi.
- In the Blueprint's Components panel, select Body Mesh and set its Static Mesh. The actor origin is the centre of the footprint on the ground, with +X forward; use the component's Location and Scale for a mesh with another pivot.
- Click Add > Ax Traffic Wheel once per wheel, attached to Vehicle Root. Set each wheel's Static Mesh (pivot at the wheel centre, axle along Y), its Location, and Wheel > Wheel Radius to the visible radius in cm after scale (35 by default).
- Compile and Save. Add the Blueprint to a vehicle type's Actor > Vehicle Classes, set the type's Length and Width to the body's footprint, and list the type in the manager's Vehicles > Vehicle Types.
Wheels roll by the distance the car moves. Paint and brake lights go through the body mesh's Custom Primitive Data: indices 0 to 2 hold the body colour, 3 the brakes (0 or 1). Build your car material on MF_AnyTraffic_VehiclePaint, or read those values directly. For per-car setup, override On Vehicle Spawned in My Blueprint > Functions > Override and call Parent: On Vehicle Spawned to keep the paint. On Vehicle Despawned and On Braking Changed are events for the Event Graph.
Reused actors keep their state. Cars are pooled: a removed car's actor is hidden and reused for the next car of its class, with its variables, attached actors and material changes. Reset them in On Vehicle Spawned or On Vehicle Despawned. An On Vehicle Spawned override that never paints leaves the previous car's colour.
7 · Performance
Collision, distant cars and debug drawing
Every car is an actor that follows the simulation. Collision is off by default, and cars that are far away and out of sight update less often.
▾ Collision and Vehicles
A car on screen always updates every frame, however far away. Only the actors are throttled: the simulation still steps every car, so spacing and junctions don't change. Stopped cars cost almost nothing, and with collision off the bodies stay out of physics. Spawning an actor is the expensive step: actors are pooled and reused, but the first fill can spawn up to Max Vehicles actors in one frame. Profile with stat game and Unreal Insights.
Draw Debug (Debug on the manager) shows each car's footprint, green and red while braking. Near a stop line it draws a line to the junction lane the car wants: green when granted, yellow when allowed but not yet committed, red when it must stop. A car waiting a second or more shows Wait N s.
8 · Limits
Limits and networking
What traffic does not do, so you can plan around it.
- Local, cosmetic traffic. Nothing replicates, the car actors included. Every machine that runs a manager, dedicated servers too, simulates its own cars. Turn Start Automatically off where traffic isn't needed.
- Collision is one-way. With collision on, car bodies block traces and push physics objects, but the simulation never reacts to them: cars react only to each other and to stop lines, and drive through, or push, whatever is in their lane.
- No pedestrians. Nobody uses the crosswalks.
- Random routes. Cars have no destinations; each picks its next lane at random.
Next: how roads are built from profiles, and how to swap in your own meshes and materials.