# Simple Traffic System

![](/files/-MDqcLurh2CKWNzBGZdt)

STS is an AI car and waypoint system, with editor helper tools that allow for quick creation of waypoint based routes that can be interconnected to create road networks in your scenes.

The primary logic is handled by a single **AI Traffic Controller** that **AI Traffic Cars** register to, it uses the C# Job System and Burst Compiler to spread processing across all available CPU cores, reducing usage on the main thread, allowing you to use more of your performance budget for other content.

90 minutes of [tutorial videos](/tutorials/video-tutorials) to help teach workflow and demonstrate available features.

{% embed url="<https://youtu.be/vr4bFaucW14>" %}
Integration with Stylized Vehicles Pack - Low Poly
{% endembed %}

## Key Features

&#x20;\- **No DLLs**: Full source provided!\
\
\- **Modular**: create, connect, and edit waypoint routes for AI cars to follow.\
\
\- **Waypoint Based**: each waypoint can set speed limit, call stop driving, be a junction to new route point(s), or trigger custom events via Unity inspector.\
\
\- **Traffic Lights**: control when AI cars can exit waypoint routes.\
\
\- **Yield Triggers**: control when AI cars can proceed to next waypoint at intersections with traffic lights.\
\
\- **Traffic Stops**: control when AI cars can exit waypoint routes.\
\
\- **Pooling System**: disables cars far away from the player, and spawn cars around the player; allows scaling up scene size without using more cars.\
\
\- **Unity Physics Components**: AI cars use Rigidbody and Wheel Colliders.\
\
\- **Vehicle Types**: define which cars can spawn/merge onto which routes.\
\
\- **Volume Sensors**: more accurate detection compared to raycasts; uses layer mask to determine which objects should be detected.

## Editor Utility Tools

\- **Supports Undo/Redo**\
\
\- **STS Tools Window**: select from various tools to help automate waypoint route configuration tasks, reducing the need to dig through the hierarchy to configure references and settings.\
\
\- **Lane Connector**: draws handles in the scene view over end of route waypoints, select 2 routes to auto configure lane change points.\
\
\- **Route Connector**: draws handles in the scene view over route waypoints to create route connections between waypoints.\
\
\- **Route Editor**: view/edit all waypoints from the selected route.\
\
\- **Signal Connector**: draws handles in the scene view over end of route waypoints and traffic lights. Used to connect/disconnect route traffic signal lights.\
\
\- **Spawn Points**: draws handles in the scene view over waypoints to manually add/remove spawn points, randomly assign spawn points to all waypoints, or remove spawn points from all waypoints.\
\
\- **Spline Route Creator**: procedurally generates multiple waypoint routes and their waypoints along a spline with a unique offset for each, allowing you to quickly create routes and waypoints on large roads with curves or inclines.\
\
\- **Stop Connector**: draws handles in the scene view over end of route waypoints and traffic stops. Used to connect/disconnect route traffic stops.\
\
\- **Yield Triggers**: draws handles in the scene view over route waypoints, and yield triggers. Used to connect/disconnect waypoints and yield triggers.


# Project Setup

STS is an AI car and waypoint system, with editor helper tools that allow for quick creation of waypoint based routes that can be interconnected to create road networks in your scenes.

The primary logic is handled by a single **AI Traffic Controller** that **AI Traffic Cars** register to, it uses the C# Job System and Burst Compiler to spread processing to across all available CPU cores, reducing usage on the main thread, allowing you to use more of your performance budget for other content.

After project setup, it’s recommended to watch and follow all video tutorials so you will have a good idea how to use the various systems included with STS before starting to configure your own road network.

#### **Project Player Settings --** Edit - Project Settings - Player

* API Compatibility Level .Net 4.x

#### Package Requirements -- packages are auto installed on import

* Burst
* Collections

Using Burst in a build is slightly different for various development platforms and build targets.

1. To use the burst compiler in standalone builds on Windows, install the Windows SDK and VC++ toolkit from the Visual Studio Installer; they're currently included when installing the **Desktop development with C++** workload.
2. If you are on a different platform, build target, or would like to learn more, please reference the [Official Burst Build Guide ](https://docs.unity3d.com/Packages/com.unity.burst@1.1/manual/index.html#standalone-player-support)from Unity Documentation for more details on your platform and build target.


# FAQ

Frequently Asked Questions

## Editor performance is lower than expected.

For the best performance in editor play mode, make sure the scene window is behind the game window. If you don't need to view the scene view gizmos, you can disable them in the Preferences window.  Edit/Preferences/Simple Traffic System&#x20;

## Editor tools don't seem to work as intended.

Often resetting the unity window layout to default (top right corner of Unity Editor) will fix editor related bugs. Unfortunately this is an unresolved Unity bug that has been around for a long time.

## Traffic cars are not spawning as expected.

When cars are spawned, the spawn point's collider bounds are checked to make sure it's empty. Ensure there are not any other objects touching the spawn point colliders.

## Collections is not available to import via Package Manager in Unity 2020.1 or 2020.2.

Please see this forum post for a guide on installing unlisted packages in 2020.1 or 2020.2: <https://forum.unity.com/threads/simple-traffic-system.794268/page-6#post-6318243>

## &#x20;How do I control the AI car speed?

AITrafficCar will set the car’s top speed, each AITrafficWaypoint will set the car’s speed limit.


# Quick Start Guide

This is a written quick start guide detailing the minimal steps to get started. For more detailed instructions, please view the [Video Tutorials](/tutorials/video-tutorials). It's strongly recommended to go through all video tutorials to gain insight into how the available systems and tools should be used.

The following video will guide you through the asset import/setup process, additional information about project setup can be found on the [Project Setup](/project-setup) page.

This asset uses AI Traffic Waypoint Routes, which are made of AI Traffic Waypoints; these routes spawn AI Traffic Car prefabs on scene start, which get registered to an AI Traffic Controller. The idea is to create multiple routes with waypoints, and link them together to create a road network, then add AI Traffic Light Managers to sequence groups of AI Traffic Lights that are used to control when a car can exit the assigned AI Traffic Waypoint Route.

Select Tools > Simple Traffic System > STS Tools Window from the Unity menu bar to open the Simple Traffic System Tools window. This window contains a variety of editor tools that can be used to help create your simulation. Many of the functions these tools provide can also be manually configured.

To begin, add an AI Traffic Controller to the scene, then add an AI Traffic Waypoint Route to the scene using the Spawn buttons in STS Tools window. Next, add AI Traffic Waypoints to the route by selecting the AI Traffic Waypoint Route that was created in the Hierarchy and using Shift+LeftClick to add new points to the route. You can use Shift+Ctrl+LeftClick to insert a new waypoint between points.

Once you’ve created your first route with some waypoints, assign an AI Traffic Car prefab to the Spawn Traffic Vehicles array on the AI Traffic Waypoint Route. Select the AI Traffic Waypoints to view their inspector options, here you can set how fast the car is allowed to drive after reaching each point to make the car speed up or slow down. Press play to watch the AI car spawn onto the route, drive to the end and stop. From here, you can continue adding more AI Traffic Waypoint Routes, and interconnect the routes by assigning the New Route Point array index on the final waypoint of a route to the first waypoint of another route.

{% embed url="<https://youtu.be/RB8_frmyyDI>" %}


# Video Tutorials

Video tutorials designed to teach workflow and get you up and running quickly.


# 1. Getting Started

{% embed url="<https://youtu.be/RB8_frmyyDI>" %}


# 2. Connecting Routes

{% embed url="<https://youtu.be/AfQXogWckz0>" %}


# 3. Traffic Lights

{% embed url="<https://youtu.be/NwbV2y_WoIc>" %}


# 4. Spline Route Creator

{% embed url="<https://youtu.be/ak6IOTmXlbw>" %}


# 5. Spawn Points

{% embed url="<https://youtu.be/-tNje4W2xo0>" %}


# 6. Lane Changing

{% embed url="<https://youtu.be/PSe_TI3Jbc0>" %}


# 7. Traffic Pooling

{% embed url="<https://youtu.be/PzH3D7gaEUM>" %}


# 8. New Car Prefabs

{% embed url="<https://youtu.be/F2o5lsN8pdM>" %}


# 9. Route Editor

{% embed url="<https://youtu.be/I-dKXQz_OfI>" %}


# 10. Deleting Waypoints

{% embed url="<https://youtu.be/_8AWaJFTOxI>" %}


# 11. Deleting and Setting Up Random Spawn Points

{% embed url="<https://youtu.be/yWBCRyFeow4>" %}


# 12. Yield Triggers

{% embed url="<https://youtu.be/JffeAGZNcIM>" %}


# 13. Preferences Window

{% embed url="<https://youtu.be/1SFQDwl-jqQ>" %}


# 14. Vehicle Types

{% embed url="<https://youtu.be/vF8Qj4PenVg>" %}


# 15. Stop Signs

{% embed url="<https://youtu.be/tMI4I_9Qqp4>" %}


# 16. Using A Player Car

{% embed url="<https://youtu.be/qo-8EgOhYF8>" %}


# 17. Multiple Routes Per Light

{% embed url="<https://youtu.be/X0Ae-Rpgwtk>" %}


# 18. Integrations

{% embed url="<https://youtu.be/PB3SDnh2gxY>" %}


# 19. Procedural Traffic and City using CiDy

{% embed url="<https://youtu.be/c33xSrNi9Gs>" %}


# 20. Auto Rig AI Traffic Car

{% embed url="<https://youtu.be/kFkwLQdtulk>" %}


# 21. URP & HDRP Demos

{% embed url="<https://youtu.be/RSPKvCJbmFU>" %}


# API

This section is under construction, please inquire if you have API related questions that are not documented.


# AITrafficCar

Primary component used on AITrafficCar prefabs, controlled by the AITrafficController.

| Variables            |                                                                                                                     |
| -------------------- | ------------------------------------------------------------------------------------------------------------------- |
| assignedIndex        | AITrafficController array index, assigned when car is registered.                                                   |
| accelerationPower    | Amount of torque that is passed to car Wheel Colliders when not braking.                                            |
| minDrag              | Minimum amount of drag applied to car Rigidbody when not braking.                                                   |
| minAngularDrag       | Minimum amount of angular drag applied to car Rigidbody when not braking.                                           |
| frontSensorSize      | Size of the front detection sensor BoxCast.                                                                         |
| frontSensorLength    | Length of the front detection sensor BoxCast.                                                                       |
| sideSensorSize       | Size of the side detection sensor BoxCasts.                                                                         |
| sideSensorLength     | Length of the side detection sensor BoxCasts.                                                                       |
| vehicleType          | Vehicles will only spawn, and merge onto routes with matching vehicle types.                                        |
| goToStartOnStop      | Respawn the car to the first route point on it's spawn route when the car comes to a stop.                          |
| topSpeed             | Car max speed, assigned to AITrafficController when car is registered.                                              |
| brakeMaterial        | Material used for brake light emission. If unassigned, the material assigned to the brakeMaterialMesh will be used. |
| brakeMaterialMesh    | If brakeMaterial is unassigned, the material assigned to the brakeMaterialIndex will be used.                       |
| brakeMaterialIndex   | Mesh Renderer material array index to get brakeMaterial from.                                                       |
| frontSensorTransform | Control point to orient/position the front detection sensor.                                                        |
| leftSensorTransform  | Control point to orient/position the left detection sensor.                                                         |
| rightSensorTransform | Control point to orient/position the right detection sensor.                                                        |
| headLight            | Light toggled on/off based on pooling cullHeadLight zone.                                                           |
| wheels               | References to car wheel mesh object, transform, and collider.                                                       |

| Public Methods           |                                                                                                        |
| ------------------------ | ------------------------------------------------------------------------------------------------------ |
| AccelerationInput        | Returns current acceleration input as a float 0-1.                                                     |
| SteeringInput            | Returns current steering input as a float -1 to 1.                                                     |
| CurrentSpeed             | Returns current speed as a float.                                                                      |
| IsBraking                | Returns current breaking input state as a bool.                                                        |
| IsLeftSensor             | Returns true if left sensor is triggered.                                                              |
| IsRightSensor            | Returns true if right sensor is triggered.                                                             |
| IsFrontSensor            | Returns true if front sensor is triggered.                                                             |
| SetTopSpeed(float)       | Updates the AITrafficController top speed value for this AITrafficCar.                                 |
| SetForceLaneChange(bool) | Controls an override flag that requests the car to attempt a lane change when able.                    |
| StartDriving             | The AITrafficCar will start driving.                                                                   |
| StopDriving              | The AITrafficCar will stop driving.                                                                    |
| MoveCarToPool            | Disables the AITrafficCar and returns it to the AITrafficController pool                               |
| DisableAIProcessing      | Stop the AITrafficController from processing component updates on the AITrafficCar and its components. |
| EnableAIProcessing       | Resume AITrafficController processing component updates on the AITrafficCar and its components.        |
| RegisterCar              | Registers the AITrafficCar with the AITrafficController for processing.                                |


# AITrafficController

Controls logic and movement for AITrafficCars using the Job System and Burst Compiler.

## Traffic Prefabs

|                |                                         |
| -------------- | --------------------------------------- |
| trafficPrefabs | Array of AITrafficCar prefabs to spawn. |

## Car Settings

| Variables               |                                                                                                                                                     |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| useYieldtriggers        | Enables the processing of YieldTrigger logic.                                                                                                       |
| speedMultiplier         | Multiplier used for calculating speed; 2.23693629 by default for MPH.                                                                               |
| steerSensitivity        | Multiplier used to control how quickly the car's front wheels turn toward the target direction.                                                     |
| maxSteerAngle           | Maximum angle the car's front wheels are allowed to turn toward the target direction.                                                               |
| stopThreshold           | Front detection sensor distance at which a car will start braking.                                                                                  |
| layerMask               | Physics layers the detection sensors can detect.                                                                                                    |
| enableLaneChanging      | Enables the processing of Lane Changing logic.                                                                                                      |
| changeLaneTrigger       | Minimum amount of time until a car is allowed to change lanes once conditions are met.                                                              |
| minSpeedToChgangeLanes  | Minimum speed required to change lanes.                                                                                                             |
| changeLaneCooldown      | Minimum time required after changing lanes before allowed to change lanes again.                                                                    |
| unassignedBrakeMaterial | Dummy material used for brake light emission logic when a car does not have an assigned brake variable.                                             |
| setCarParent            | AI Cars will be parented to the 'Car Parent' transform, this AITrafficController will be the parent if a parent is not assigned.                    |
| carParent               | If 'Set Car Parent' is enabled, AI Cars will be parented to this transform, this AITrafficController will be the parent if a parent is not defined. |

## Pooling

| Variables     |                                                                                                                                  |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| usePooling    | Enables the processing of Pooling logic.                                                                                         |
| centerPoint   | Transform that pooling distances will be checked against.                                                                        |
| useRouteLimit | When using pooling, cars will not spawn to a route if the route limit is met.                                                    |
| density       | Max amount of cars the pooling system is allowed to spawn.                                                                       |
| spawnRate     | Frequency at which pooling spawn is performed.                                                                                   |
| minSpawnZone  | Cars can't spawn or despawn in this zone.                                                                                        |
| cullHeadLight | Car headlights will be disabled outside of this zone.                                                                            |
| activeZone    | Cars only spawn if the spawn point is not visible by the camera.                                                                 |
| spawnZone     | Cars can spawn anywhere in this zone, even if spawn point is visible by the camera. Cars outside of this zone will be despawned. |

| Public Methods |   |
| -------------- | - |
|                |   |


# AITrafficLight

The tutorial workflow has this component controlled by AITrafficLightManager, but you can also write your own scripts to control a light for a route.

| Variables      |                                                                                            |
| -------------- | ------------------------------------------------------------------------------------------ |
| redMesh        | Red light mesh, disabled for green and yellow.                                             |
| yellowMesh     | Yellow light mesh, disabled for green and red.                                             |
| greenMesh      | Green light mesh, disabled for red and yellow.                                             |
| waypointRoute  | Route to control, cars can't exit assigned route if light is red or yellow.                |
| waypointRoutes | List of routes to be controlled, cars can't exit assigned route if light is red or yellow. |

| Public Methods    |                                                                 |
| ----------------- | --------------------------------------------------------------- |
| EnableRedLight    | Cars can't exit route. Red mesh enabled, green/yellow disabled. |
| EnableYellowLight | Cars can't exit route. Yellow mesh enabled, green/red disabled. |
| EnableGreenLight  | Cars can exit route. Green mesh enabled, red/yellow disabled.   |


# AITrafficLightManager

Controls groups of AITrafficLights for an intersection.

On Start will set all AITrafficLights assigned to red, then begin the configured sequence.

| Variables          |                                                            |
| ------------------ | ---------------------------------------------------------- |
| trafficLightCycles | Array of AITrafficLightCycles played as a looped sequence. |

## AITrafficLightCycle

| Variables     |                                                     |
| ------------- | --------------------------------------------------- |
| greenTimer    | Green light duration.                               |
| yellowTimer   | Yellow light duration.                              |
| redTimer      | Red light duration.                                 |
| trafficLights | Array of AITrafficLights that follow this sequence. |


# AITrafficStop

The tutorial workflow has this component controlled by AITrafficStopManager, but you can also write your own scripts to control a stop for a route.

| Variables      |                                                                      |
| -------------- | -------------------------------------------------------------------- |
| waypointRoute  | Cars can't exit assigned route until AITrafficStopManager allows it. |
| stopForTraffic | Read only bool returns the current status of the stop.               |

| Public Methods    |                        |
| ----------------- | ---------------------- |
| StopTraffic       | Cars can't exit route. |
| AllowCarToProceed | Cars can exit route.   |


# AITrafficStopManager

Controls groups of AITrafficStops for an intersection.

On Start will set all AITrafficStops to stop, then begin the configured sequence.

| Variables  |                                                           |
| ---------- | --------------------------------------------------------- |
| stopCycles | Array of AITrafficStopCycles played as a looped sequence. |

## AITrafficStopCycle

| Variables    |                                                               |
| ------------ | ------------------------------------------------------------- |
| activeTime   | Amount of time cars are allowed to proceed before next cycle. |
| waitTime     | Amount of time before next cycle becomes active.              |
| trafficStops | Array of AITrafficLights that follow this sequence.           |


# AITrafficWaypoint

When the car reaches each waypoint, a variety of settings can be configured, like setting a new speed limit, stop driving, move to a new route, trigger custom events, and more.

| Variables               |                                                                                                                      |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------- |
| onReachWaypointSettings | Contains settings and references to components triggered by the attached collider's OnTriggerEnter(Collider) method. |

| Public Methods                |                                                             |
| ----------------------------- | ----------------------------------------------------------- |
| RemoveMissingLaneChangePoints | Empties the onReachWaypointSettings.newRoutePoints array.   |
| RemoveMissingNewRoutePoints   | Empties the onReachWaypointSettings.laneChangePoints array. |

## AITrafficWaypointSettings

| Variables            |                                                                                                                                                                                                 |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| parentRoute          | Reference to the waypoint's parent route.                                                                                                                                                       |
| waypoint             | Reference to the waypoint.                                                                                                                                                                      |
| nextPointInRoute     | Reference to the next waypoint in route.                                                                                                                                                        |
| waypointIndexnumber  | Waypoint Route array index of the waypoint.                                                                                                                                                     |
| speedLimit           | Speed limit the car will use after reaching the waypoint.                                                                                                                                       |
| stopDriving          | Controls if the car will stop driving after reaching a waypoint.                                                                                                                                |
| stopTime             | Set stop time greater than 0 to restart the car after the stop time duration.                                                                                                                   |
| newRoutePoints       | Array of route points the car can choose randomly after reaching a waypoint.                                                                                                                    |
| laneChangePoints     | Array of route points the car can choose randomly based on sensor conditions to change to for obstacle avoidance.                                                                               |
| yieldTriggers        | Array of YieldTriggers the car will check for, if the yield trigger's assigned route has a green light and is being triggered the car will stop until the trigger is empty or the light is red. |
| OnReachWaypointEvent | Custom event that is triggered when the car reaches a waypoint.                                                                                                                                 |


# AITrafficWaypointRoute

Holds an array of waypoints used for path-finding, updating car settings, and triggering events.

| **Scene View Commands**   |                                                                  |
| ------------------------- | ---------------------------------------------------------------- |
| Shift + Left Click        | In scene view on a Collider to add new points to the route.      |
| Shift + Ctrl + Left Click | In scene view on a Collider to insert new points to the route.   |
| Shift + Right Cllick      | In scene view on a Collider to add a Yield Trigger to the route. |

| Inspector Buttons         |                                                                      |
| ------------------------- | -------------------------------------------------------------------- |
| Reverse Waypoints         | Reverses all waypoints in the route's waypointDataList.              |
| Align Waypoints           | Aligns the rotation of all waypoints to face toward the next point.  |
| Setup Random Spawn Points | First removes all spawn points, then randomly adds new spawn points. |
| Remove All Spawn Points   | Removes all spawn points from the route.                             |

| Variables                    |                                                                                                                        |
| ---------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| vehicleTypes                 | Array of vehicles types that are allowed to spawn and merge onto this route.                                           |
| waypointDataList             | List of waypoints in the route that cars will use for path-finding.                                                    |
| spawnFromAITrafficController | AITrafficController trafficPrefabs array will populate spawnTrafficVehicles array.                                     |
| spawnTrafficVehicles         | Array of traffic car prefabs instantiated to the route on startup.                                                     |
| spawnAmount                  | Amount of cars to spawn.                                                                                               |
| useSpawnPoints               | Startup traffic will use spawn points, instead of incrementally spawning every other waypoint.                         |
| maxDensity                   | Amount of cars allowed on the route by startup and pooling spawners.                                                   |
| stopForTrafficLight          | Controlled by the route's AITrafficWaypointRouteInfo script and traffic lights; determines if cars can exit the route. |
| routeInfo                    | Reference to the route's AITrafficWaypointRouteInfo script.                                                            |

| Public Methods |   |
| -------------- | - |
|                |   |


# AITrafficWaypointRouteInfo

Controls if cars can exit route, or if yield trigger is active requiring cross traffic to stop.

| Variables            |                                                                                     |
| -------------------- | ----------------------------------------------------------------------------------- |
| stopForTrafficLight  | Controls if cars can exit route, set by traffic lights.                             |
| yieldForTrafficLight | Controls if this route requires cross traffic to yield, set by AITrafficController. |
| yieldTrigger         | Box Collider used to set bounds for yield area.                                     |


# SplineRouteCreator

Generates multiple AI Traffic Waypoint Routes and their Waypoints along a spline.

| Inspector Buttons |                                                                                   |
| ----------------- | --------------------------------------------------------------------------------- |
| Start New         | Release the waypoint routes from the Spline Route Creator, and create new routes. |
| Refresh           | Refreshes the routes based on current spline and inspector settings.              |

| Variables         |                                                                          |
| ----------------- | ------------------------------------------------------------------------ |
| routes            | Number of routes to build along the spline.                              |
| waypointFrequency | Distance percentage at which points will be placed along the spline.     |
| defaultOffset     | Position offset applied to each routes waypoints from the spline points. |

| Public Methods       |                                                                     |
| -------------------- | ------------------------------------------------------------------- |
| AddPoint(Vector3)    | Adds a new spline point to the end of the spline.                   |
| InsertPoint(Vector3) | Adds a new spline point between the closest 2 points on the spline. |


# Asset Integrations


# IK Avatar Driver

{% embed url="<https://youtu.be/_HaOGVF9wKk>" %}


# Stylized Vehicles Pack - Low Poly

{% embed url="<https://youtu.be/vr4bFaucW14>" %}


# Demo Scenes

2 primary demo scenes are included, Demo and Demo Pooling, they both have the same scene content. The difference between them are on the AITrafficController, specifically the Demo Pooling scene has pooling enabled, with it's center point assigned to the main camera.


# Prefabs

This section explains how prefabs are used, and where the prefab objects are located.


# AITrafficCar

Located at: Assets\TurnTheGameOn\SimpleTrafficSystem\Prefabs\\

The base car prefab used by the traffic system. Duplicate this prefab and replace the mesh with your own to create new vehicles.


# AITrafficController

Located at: Assets\TurnTheGameOn\SimpleTrafficSystem\Resources\AITrafficController

This is the primary logic controller for AI cars. There must be only one in the scene (it’s a singleton) for AI cars to register to.


# AITrafficSpawnPoint

Located at: Assets\TurnTheGameOn\SimpleTrafficSystem\Resources\AITrafficSpawnPoint

Please note that the **Mesh Renderer** and **Box Collider** components attached to this prefab are required and used by the pooling system. This is an intentional design decision that was made in order to utilize the following built in Unity callbacks to check the bounds of a spawn point, and the visibility of the spawn point by the camera; if the collider bounds are empty and the mesh renderer is not visible by the camera, cars are allowed to spawn.

Links to builtin callbacks utilized by the AITrafficSpawnPoint component:

* [OnTriggerEnter](https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html)
* [OnTriggerExit](https://docs.unity3d.com/ScriptReference/Collider.OnTriggerExit.html)
* [OnTriggerStay](https://docs.unity3d.com/ScriptReference/Collider.OnTriggerStay.html)
* [OnBecameVisible](https://docs.unity3d.com/ScriptReference/Renderer.OnBecameVisible.html)
* [OnBecameInvisible](https://docs.unity3d.com/ScriptReference/Renderer.OnBecameInvisible.html)


# AITrafficWaypointRoute

Located at: Assets\TurnTheGameOn\SimpleTrafficSystem\Resources\AITrafficWaypointRoute<br>

These are the core building blocks used to create road networks. The demo scene has about 100 interconnected AI Traffic Waypoint Routes.


# AITrafficWaypoint

Located at: Assets\TurnTheGameOn\SimpleTrafficSystem\Resources\AITrafficWaypoint

These are used and spawned by AI Traffic Waypoint Routes by pressing Shift+LeftClick in the scene view on a collider. Set the speed limit for each point to control how fast you want traffic to travel. Interconnect routes by assigning the New Route Point array index on the final waypoint of a route to the first waypoint of another route.


# AITrafficLightManager

Located at: Assets\TurnTheGameOn\SimpleTrafficSystem\Resources\AITrafficLightManager

These control groups of AI Traffic Lights by sequencing Traffic Light Cycles based on timers set for each sequence. Each Traffic light cycle holds an array of Traffic Lights which hold a reference to AI Traffic Waypoint Routes. Once a route is assigned to a traffic light, the light will control if the car at the final waypoint is allowed to proceed through the intersection to the next connected waypoint route.


# AITrafficStopManager

Located at: Assets\TurnTheGameOn\SimpleTrafficSystem\Resources\AITrafficStopManager

These control groups of AI Traffic Lights by sequencing Traffic Light Cycles based on timers set for each sequence. Each Traffic light cycle holds an array of Traffic Lights which hold a reference to AI Traffic Waypoint Routes. Once a route is assigned to a traffic light, the light will control if the car at the final waypoint is allowed to proceed through the intersection to the next connected waypoint route.


# SplineRouteCreator

Assets\TurnTheGameOn\SimpleTrafficSystem\Resources\AITrafficWaypointRouteCreator

This tool is a prefab that can generate multiple AI Traffic Waypoint Routes and their Waypoints along a spline.


# STS Tools Window

Available to help automate and reduce the amount of work required when configuring routes for large road sections or networks; these reduce the need to manually select waypoints in the scene hierarchy to make configurations.

Select **​Tools > Simple Traffic System > STS Tools Window**​ from the Unity menu bar to open the Simple Traffic System Tools window. This window contains a variety of editor tools that can be used to create your simulation.

***Note:** The asset can be used without the tools window by manually assigning the relevant references to AITrafficWaypoints, however the window enables you to use a variety of editor scene tools to make creating and customizing your waypoint routes and waypoint connections much easier.*

{% content-ref url="/pages/-MCe26BgE7CByceL3r58" %}
[Spawn Buttons](/documentation/sts-tools-window/spawn-buttons)
{% endcontent-ref %}

{% content-ref url="/pages/-MDbl1Cg-xOktaVJsG6U" %}
[Configure Mode](/documentation/sts-tools-window/configure-mode)
{% endcontent-ref %}


# Spawn Buttons

These buttons will instantiate the named object into the scene.


# AI Traffic Controller

This is the primary logic controller for AI cars. There must be only one in the scene (it’s a singleton) for AI cars to register to.

More information about this prefab can be found in the prefabs section.

{% content-ref url="/pages/-MDbW-2JhhTCUFgxI0L7" %}
[AITrafficController](/documentation/prefabs/aitrafficcontroller)
{% endcontent-ref %}


# AI Traffic Waypoint Route

These are the core building blocks used to create road networks. The demo scene has about 100 interconnected AI Traffic Waypoint Routes.

More information about this prefab can be found in the prefabs section.

{% content-ref url="/pages/-MDbWC8znhDxDnNxSXn3" %}
[AITrafficWaypointRoute](/documentation/prefabs/aitrafficwaypointroute)
{% endcontent-ref %}


# AI Traffic Light Manager

These control groups of AI Traffic Lights by sequencing Traffic Light Cycles based on timers set for each sequence. Each Traffic light cycle holds an array of Traffic Lights which hold a reference to AI Traffic Waypoint Routes. Once a route is assigned to a traffic light, the light will control if the car at the final waypoint is allowed to proceed through the intersection to the next connected waypoint route.

More information about this prefab can be found in the prefabs section.

{% content-ref url="/pages/-MDbWbE6u7Kq63Xa96D6" %}
[AITrafficLightManager](/documentation/prefabs/aitrafficlightmanager)
{% endcontent-ref %}


# AI Traffic Stop Manager

These control groups of AI Traffic Stops by sequencing Traffic Stop Cycles based on timers set for each sequence. Each Traffic stop cycle holds an array of Traffic Stops which hold a reference to AI Traffic Waypoint Routes. Once a route is assigned to a traffic light, the light will control if the car at the final waypoint is allowed to proceed through the intersection to the next connected waypoint route.

More information about this prefab can be found in the prefabs section.

{% content-ref url="/pages/-MFChhfhbzv2FHvmjK3X" %}
[AITrafficStopManager](/documentation/prefabs/aitrafficstopmanager)
{% endcontent-ref %}


# Spline Route Creator

This tool can generate multiple AI Traffic Waypoint Routes and their Waypoints along a spline.

More information about this prefab can be found in the prefabs section.

{% content-ref url="/pages/-MDbnm5XO2L6LkffejQm" %}
[Spline Route Creator](/documentation/sts-tools-window/spawn-buttons/spline-route-creator)
{% endcontent-ref %}


# Configure Mode

Switch between SceneView tools.


# Lane Connector

Used to connect waypoint routes for lane changing. Select Load Routes to load all routes from the scene into the editor. Use the scene view handles to select 2 adjacent “Routes“, handle buttons are located above the final route point. Press Setup Lane Change Points to create a connection.


# Route Connector

Select Load Routes to load all routes from the scene into the editor. Use the scene view handle to select “From and To points”, handle buttons are located above each waypoint. Press Connect Route Points to create a connection.


# Route Editor

Used to more-easily view and modify all waypoints from the selected route in a single window. Select Load Routes to load all routes from the scene into the editor. Use the scene view handle buttons to select a route, handle buttons are located above the final route point.


# Signal Connector

Select Load Lights & Routes to load all traffic lights and routes from the scene into the editor. Use the scene view handle to select “From Light and To Route points”, handle buttons are located above the final route point and traffic signal. Press Connect Light to Route to assign a connection. This window is also useful to visually debug which traffic light signal is connected to which route.


# Spawn Points

Used to configure spawn points for a more randomized spawning pattern, this is required by the traffic pooling system. Select Load Routes to load all routes from the scene into the editor. Select Align Route Waypoints to have each waypoint’s transform orientation set to face the next waypoint in the route. When routes are loaded, a scene handle button named S is placed above each waypoint in the scene. Press this button to load an AITrafficSpawnPoint into the scene as a child of that point.


# Stop Connector

Select Load Stops & Routes to load all traffic stops and routes from the scene into the editor. Use the scene view handle to select “From Stop and To Route points”, handle buttons are located above the final route point and traffic signal. Press Connect Stop to Route to assign a connection. This window is also useful to visually debug which traffic stops are connected to which route.


# Yield Triggers

\*Attaching to  a route requires the route to have a traffic light controlling it.

Allows a box collider to be used as a trigger zone that detect vehicles in or approaching an intersection from a waypoint route. Any waypoint can be setup to yield while this trigger is active. This is useful if a route intersects with another route when traffic signal lights are not used, a good example is intersection turning lanes. Select Load Routes to load all routes from the scene into the editor. Use the scene view handle to select a “R” handle button located above the final route point to select a route for editing. Select the “WP” handle button above the route waypoints to configure the waypoint to yield for a yield trigger. Select the “Y” handle button above the final waypoint on the route yield triggers are connected to. Select an AITrafficWaypointRoute from the scene and Shit + Right click in the scene view to auto spawn and assign the trigger to the route’s AITrafficWaypointRouteInfo script.


