> 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/addexcludedvehicle.md).

# AddExcludedVehicle

### Description

Excluded vehicles are a special kind of vehicle marked as **Don't Instantiate** inside the Vehicle Pool. These vehicles will not be instantiated by the system unless the user specifies to be instantiated using this method. Read more about them [Vehicle Pool](/mobile-traffic-system/setup-guide/vehicle-pool.md#add-vehicles-to-the-pool)

The AddExcludedVehicle method will instantiate an excluded vehicle, the vehicle will work normally, but when it is removed it will not be instantiated again. Call [AddExcludedVehicleToSystem ](/mobile-traffic-system/complete-api/addexcludedvehicletosystem.md)to make it behave like a regular traffic vehicle.

If the index sent as a parameter is not an excluded vehicle, it will be ignored.

### Declaration&#x20;

```csharp
public static void AddExcludedVehicle(int vehicleIndex, Vector3 position)

public static void AddExcludedVehicle(int vehicleIndex, Vector3 position, UnityAction<VehicleComponent, int> completeMethod)
```

### Parameters

<table><thead><tr><th width="188">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>vehicleIndex</strong></td><td>Index of the excluded vehicle.</td></tr><tr><td><strong>position</strong></td><td>The instantiation location. it will be the closest waypoint to this position. </td></tr><tr><td><strong>completeMethod</strong></td><td>Callback triggered after instantiation. It returns the VehicleComponent and the waypoint index where the vehicle was instantiated. </td></tr></tbody></table>

### Example

```csharp
GameObject instantiateLaterVehicle;

//after the traffic system is initialized
void OnTrafficInitializedCallback()
{
    //get the complete list of excluded vehicle
    List<VehicleComponent> excludedVehicle = API.GetExcludedVehicleList();

    foreach (VehicleComponent vehicleComponent in excludedVehicle)
    {
        if (vehicleComponent.vehicleType == VehicleTypes.SomeType)
        {
            //do something
            //save the vehicle
            //do whatever you want

            //I will save the GamaObject for later use
            instantiateLaterVehicle = vehicleComponent.gameObject;
        }
    }
}

//at the right time instantiate the vehicle using one of those 2 options
void InstantiateExcludedVehicle()
{
    //manually add vehicle to a specified position
    API.AddExcludedVehicle(API.GetExcludedVehicleIndex(instantiateLaterVehicle), position);

    //add the vehicle to the system and it will be automatically instantiated like any other vehicle
    API.AddExcludedVehicleToSystem(API.GetExcludedVehicleIndex(instantiateLaterVehicle));
}
```
