Prepare Scene

For the Traffic System to work some scene and layer setup is needed.

Layer setup

Mobile Traffic System uses layers for performance optimization. make sure to properly set the layers inside your project otherwise weird things can happen like cars spawning on top of each other or falling through the road.

Open: Settings Window -> Scene Setup -> Layer Setup

Available Layers

Road Layers - The vehicle's wheels will only collide with objects assigned to the layers marked as Road. To ensure proper functionality, all-terrain, roads, sidewalks, and any other surfaces the vehicles will drive on should be included in this layer mask.

Traffic Layers - This layer mask is exclusively for traffic vehicles. Ensure that all the colliders of the vehicles are assigned to layers included in this mask. Improper setup may result in cars colliding or spawning on top of each other.

Building Layers - This layer mask is intended for static objects such as buildings, lampposts, and other stationary elements situated near the road. In extreme conditions, such as crashes, vehicles might collide with these objects.

Obstacle Layers - This layer mask should contain dynamic objects that may intersect the roads, requiring traffic vehicles to detect and avoid collisions with them.

Player Layers - designated for the player's car/character. The distinction between this layer and dynamic objects lies in the potential for setting specific actions for the player, differing from other objects within the application.

Collision matrix

For performance optimization, it is better to mark layers that you know will never collide to improve the physics computation.

Please read more info about how to do that here:

Grid Setup

To accommodate large scenes, the system employs a grid-based setup. This approach ensures that the scene's dimensions do not impact the Traffic System's performance. Utilizing a pooling system, the system spawns and despawns vehicles selectively around the player, creating the illusion of high traffic density with fewer vehicles, thereby improving performance.

To edit the grid size open: Settings Window -> Scene Setup -> Grid Setup

The grid cell size is in meters usually something between 50 and 100 works best for cities. Click Regenerate Grid to update the grid size at the new dimension.

The View Grid button will display the grid inside the Scene view.

How does the grid work?

The grid is used to mark the cells around the player as active and the other ones as inactive. Here you can see an example:

The player is located inside the blue rectangle so its grid cell and all the cells adjacent to it are marked as active.

The level of active squares can be increased using the API to extend the number of active cells.

The cells marked with green 'X' are designated as active cells. Vehicles will spawn exclusively within these cells, and intersections will function only within these active cells. If an intersection occupies cells marked with a red X at all times, a single road will remain active constantly, and nothing will update. This is done to save computation power. When those cells become active, the intersection will behave normally without any noticeable impact on the player.

Here are some configuration tips:

If you want higher vehicle density around the player, you should reduce the cell size to force vehicle spawning closer to the player. This works best for cities when the player turns very often.

If you are primarily using highways, you might consider increasing the cell size. This adjustment allows vehicles to spawn further ahead as driving mainly occurs in a straight line.

For higher speeds, larger cell sizes are more suitable. This is because the player spends very little time in a single cell, and with smaller cells, vehicles might not respawn quickly enough ahead of the player, potentially causing the road to appear empty.

Depending on your environment type and vehicle speed, different grid sizes—either larger or smaller—may work more effectively. Therefore, experimenting with various dimensions is recommended to determine the optimal size for your game type.

Every time you change the Grid Size don't forget to press the Apply Settings button on the home of the Settings Window.

Every time you change to a new platform you have to press Apply Settings to enable the plugin for the new platform.

Video Tutorial

This tutorial was made for the old version of the plugin, but all information from it is still valid.

Last updated