# Vehicles

A Vehicle component represents an object that the player can control to move around in the game world.

### Creating A Vehicle

To begin creating a new vehicle of any kind, create a new game object in the scene and add a **Vehicle** component.

### Destroying/Restoring Vehicles

Like Game Agents, vehicles can be destroyed or restored during gameplay. Here is some code to help you understand how you can do this:

```
// Destroy a vehicle
myVehicle.Destroy();

// Restore a vehicle
myVehicle.Restore();

// Check if the vehicle is destroyed
if (myVehicle.Destroyed)
{
    // Some code
}
```

### Vehicle Occupant

Sometimes you might want to know what game agent is controlling a vehicle.

```
// Get vehicle occupants
List<GameAgents> occupants = myVehicle.Occupants;
```

**Note** that the Vehicle component has been scripted to allow for multiple occupants, but currently the kits only support one occupant per vehicle. So the list will normally have one member when a vehicle is occupied, and be empty when it is not.

Sometimes you might want to do something different when a player enters the vehicle vs when an AI enters the vehicle, or when the occupant exits a vehicle. You will find Unity Events in the inspector you can add functions to that you wish to be called when any of these events occur.

### Module Mounts

To get all the module mounts on a vehicle, or add/remove a module mount, use the following code:

```
// Get a list of all the module mounts on the vehicle
List<ModuleMount> moduleMounts = vehicle.ModuleMounts;

// Add a module mount to the vehicle
myVehicle.AddModuleMount(someModuleMount);

// Remove a module mount from the vehicle
myVehicle.RemoveModuleMount(someModuleMount);
```

### Vehicle Classes

The Vehicle Class (which is a Scriptable Object) provides a way to differentiate between vehicles, for example for running specific input scripts or camera controllers.

To create a new Vehicle Class, right click in the Project view and select *Create > VSX > Vehicle Class*.

This will create a new Vehicle Class object in your Assets folder, which you can rename.

To assign a Vehicle Class to a Vehicle, simply drag the Vehicle Class object you created into the 'Vehicle Class' field in the inspector of the **Vehicle** component.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vsxgames.gitbook.io/universal-vehicle-combat/core-framework/vehicles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
