> For the complete documentation index, see [llms.txt](https://gley.gitbook.io/mobile-traffic-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gley.gitbook.io/mobile-traffic-system/complete-api/settrafficdensity.md).

# SetTrafficDensity

### Description

Modify the number of active vehicles around the player. This number cannot be greater than the maximum number of vehicles set at initialize.&#x20;

If the new number of active vehicles is less than the current active vehicles, the removing process will continue normally but no new vehicles will be instantiated until the active number of vehicles is less than the nrOfVehicles set inside the SetTrafficDensity method.&#x20;

### Declaration&#x20;

```csharp
 public static void SetTrafficDensity(int nrOfVehicles)
```

### Parameters

<table><thead><tr><th width="188">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>nrOfVehicles</strong></td><td>The new number of active vehicles.</td></tr></tbody></table>

### Example

```csharp
using Gley.TrafficSystem;
using UnityEngine;

public class Test : MonoBehaviour
{
    //a reference to vehicle pool and player assigned in inspector
    public VehiclePool vehiclePool;
    public Transform player;

    void Start()
    {
        API.Initialize(player, 20, vehiclePool);
    }

    public void ChangeDensity()
    {
        //the parameter needs to be <= 20 since the initialization declared a maximum number of 20 vehicles
        API.SetTrafficDensity(10);
    }
}

```
