# Objectives

{% embed url="<https://vimeo.com/912142589>" %}
Learn how to add player objectives to your game.
{% endembed %}

The Objectives system enables you to create objectives for the player to complete, and display them in a list on the UI.

### Quick Setup

{% hint style="info" %}
These instructions focus on creating Destroy objectives, which are objectives that are completed when specific targets in the scene are destroyed. The process is the same for all other objective types.
{% endhint %}

1. Add a damageable object to your scene.
2. Add a **Destroy Objective** component somewhere in your scene and customize the description in the inspector.
3. Drag the damageable object from Step 1 into the *Targets* list.
4. Drag the *ObjectivesUI* prefab into the scene.
5. Play the game! Now the objective appears on the left hand side of the HUD, and when the target is destroyed, a sound effect and text animation plays.

### Adding Objectives

If you want to add more targets to the same objective, just drag each one into the Targets list in the inspector of the Destroy Objective component. The UI will automatically display the total number of sub-objectives, and the number of sub-objectives that have been destroyed.

You can add any number of additional objectives to the scene by adding more **Destroy Objective** components (or any components that extend the **Objective Controller** base class, for other types of objectives). They will be automatically displayed on the UI.

### Creating Your Own Objectives

With a little coding you can create all kinds of custom objectives for your game.

The **Objective Controller** base class (which the **Destroy Objective** derives from) can be extended with your code to create all kinds of other objectives. Simply by adding these objectives to the scene, they will be displayed on the UI.

1. To begin, create your own script that extends the **Objective Controller** base class.
2. Next, override the *Is Completed* function with your code that checks if an objective is completed or not. It should return *True* if the objective is completed, or *False* if it is not, like so.

```
// My objective controller
public class MyObjectiveController : ObjectiveController
{
    protected override bool IsCompleted
    {
        // Add your own code to check if the objective is completed. Return True
        // if completed, or False if not.
    }
}
```

3. Then, anytime something happens with the objective that may indicate that its state has changed, simply call the *On Objective Changed* function, and the rest will be handled automatically.

### Adding Waypoints

You may want to add waypoints to objectives that become active when the player is far from the objective, and are deactivated as they approach.

1. Add a new gameobject to the scene and call it 'Waypoint' (or whatever you wish)
2. Drag it into a position near the objective location.
3. Add a **Trackable** component and set the *Trackable Type* to Waypoint.
4. Add a **Game Agent Trigger** component and set the distance threshold where you want the waypoint to be activated.
5. In the *On Triggered* event, drag in the **Trackable** component and call its *Set Activation* function (setting it to *False*).
6. In the *On Trigger Reset* event, drag in the **Trackable** component and call its *Set Activation* function (setting it to *True*).

The waypoint should appear on the HUD, if you need to troubleshoot that refer to the HUD documentation.


---

# 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/objectives.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.
