Objectives
Learn how to create player objectives in your game.
Last updated
Learn how to create player objectives in your game.
Last updated
The Objectives system enables you to create objectives for the player to complete, and display them in a list on the UI.
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.
Add a damageable object to your scene.
Add a Destroy Objective component somewhere in your scene and customize the description in the inspector.
Drag the damageable object from Step 1 into the Targets list.
Drag the ObjectivesUI prefab into the scene.
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.
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.
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.
To begin, create your own script that extends the Objective Controller base class.
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.
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.
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.
Add a new gameobject to the scene and call it 'Waypoint' (or whatever you wish)
Drag it into a position near the objective location.
Add a Trackable component and set the Trackable Type to Waypoint.
Add a Game Agent Trigger component and set the distance threshold where you want the waypoint to be activated.
In the On Triggered event, drag in the Trackable component and call its Set Activation function (setting it to False).
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.