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

# GetExcludedVehicleIndex

### Description

Converts the excluded vehicle GameObject into its corresponding vehicle index.

### Declaration&#x20;

```csharp
public static int GetExcludedVehicleIndex(GameObject vehicle)
```

### Parameters

<table><thead><tr><th width="188">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>vehicle</strong></td><td>The root GameObject of an excluded vehicle.</td></tr></tbody></table>

### Returns

**int** - the vehicle index (-1 = error)

### 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));
}
```
