# Objective

Kind: Class · Namespace: Sansar.Simulation · Assembly: Sansar.Simulation.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Simulation">Namespace <a href="/scripting/api/sansar.simulation"><code>Sansar.Simulation</code></a></span>
<span>Inherits <a href="/scripting/api/sansar.script/instanceinterface">Sansar.Script.InstanceInterface</a></span>
<span class="api-badge api-since">Added in 34.7.0</span>
</div>

<span id="T:Sansar.Simulation.Objective"></span>

The Objective is the interface for a user&#39;s Quest Objective

```csharp
public class Objective : Sansar.Script.InstanceInterface
```

## Members at a glance

| Kind | Members |
|---|---|
| **Properties** | [Agent](#agent) · [Count](#count) · [Definition](#definition) · [Ready](#ready) |
| **Methods** | [GetState](#getstate) · [SetState](#setstate) · [Subscribe](#subscribe) · [ToString](#tostring) · [Update](#update) |

## Properties

### Agent

<div class="api-card">
<span id="P:Sansar.Simulation.Objective.Agent"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 34.7.0</span></div>

```csharp signature
public Sansar.Script.SessionId Agent { get; }
```

The session Id for the user on this quest.

</div>

### Count

<div class="api-card">
<span id="P:Sansar.Simulation.Objective.Count"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 36.3.0</span></div>

```csharp signature
public int Count { get; set; }
```

Get the number of objectives collected for this user.

<details class="api-remarks"><summary>Remarks</summary>

Returns -1 if the Objective is not Ready.

</details>

</div>

### Definition

<div class="api-card">
<span id="P:Sansar.Simulation.Objective.Definition"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 34.7.0</span></div>

```csharp signature
public ObjectiveDefinition Definition { get; }
```

The [`QuestDefinition`](/scripting/api/sansar.simulation/questdefinition) for this quest.

</div>

### Ready

<div class="api-card">
<span id="P:Sansar.Simulation.Objective.Ready"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 36.7.0</span></div>

```csharp signature
public bool Ready { get; }
```

If the Objective data is ready.

<details class="api-remarks"><summary>Remarks</summary>

Returns false until the data has been fetched from the quest service. Once it returns true it will always return true.

</details>

</div>


## Methods

### GetState

<div class="api-card">
<span id="M:Sansar.Simulation.Objective.GetState"></span>
<span id="M:Sansar.Simulation.Objective.GetState()"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 34.7.0</span></div>

```csharp signature
public ObjectiveState GetState()
```

The [`ObjectiveState`](/scripting/api/sansar.simulation/objectivestate) representing the user&#39;s progress in the quest

**Returns:** [ObjectiveState](/scripting/api/sansar.simulation/objectivestate)

</div>

### SetState

<div class="api-card" id="setstate-objectivestate">
<span id="M:Sansar.Simulation.Objective.SetState(Sansar.Simulation.ObjectiveState)"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 34.7.0</span></div>

```csharp signature
public void SetState(ObjectiveState state)
```

Set the state of the objective.

| Parameter | Type | Description |
|---|---|---|
| `state` | [ObjectiveState](/scripting/api/sansar.simulation/objectivestate) | The state to transition to. |

<details class="api-remarks"><summary>Remarks</summary>

Some state changes may not be permitted, in these cases [`OperationCompleteEvent`](/scripting/api/sansar.script/operationcompleteevent) success will be false.

</details>

</div>

<div class="api-card" id="setstate-objectivestate-action">
<span id="M:Sansar.Simulation.Objective.SetState(Sansar.Simulation.ObjectiveState,System.Action{Sansar.Script.OperationCompleteEvent})"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 34.7.0</span></div>

```csharp signature
public void SetState(
    ObjectiveState state,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Set the state of the objective.

| Parameter | Type | Description |
|---|---|---|
| `state` | [ObjectiveState](/scripting/api/sansar.simulation/objectivestate) | The state to transition to. |
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

Some state changes may not be permitted, in these cases [`OperationCompleteEvent`](/scripting/api/sansar.script/operationcompleteevent) success will be false.

</details>

</div>

### Subscribe

<div class="api-card">
<span id="M:Sansar.Simulation.Objective.Subscribe(Sansar.Simulation.ObjectiveState,System.Action{Sansar.Simulation.ObjectiveData},System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 34.7.0</span></div>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    ObjectiveState State,
    Action<ObjectiveData> callback,
    bool persistent
)
```

Subscribes to Objective Events.

| Parameter | Type | Description |
|---|---|---|
| `State` | [ObjectiveState](/scripting/api/sansar.simulation/objectivestate) | The state of the objective |
| `callback` | [Action&lt;ObjectiveData&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Callback which is executed when the event completes. |
| `persistent` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Optional, set to false to unsubscribe after one event. |

**Returns:** [Sansar.Script.IEventSubscription](/scripting/api/sansar.script/ieventsubscription) — An [`IEventSubscription`](/scripting/api/sansar.script/ieventsubscription) that can be used to cancel the subscription.

</div>

### ToString

<div class="api-card">
<span id="M:Sansar.Simulation.Objective.ToString"></span>
<span id="M:Sansar.Simulation.Objective.ToString()"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 34.7.0</span></div>

```csharp signature
public override string ToString()
```

A string representation of this object.

**Returns:** [string](https://learn.microsoft.com/dotnet/api/system.string) — A string representation of this object.

<details class="api-remarks"><summary>Remarks</summary>

The format of this string may change between releases.

</details>

</div>

### Update

<div class="api-card" id="update-noargs">
<span id="M:Sansar.Simulation.Objective.Update"></span>
<span id="M:Sansar.Simulation.Objective.Update()"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 36.7.0</span></div>

```csharp signature
public void Update()
```

Update the ObjectiveDefinition data.

<details class="api-remarks"><summary>Remarks</summary>

Use in a WaitFor to wait for the data for the QuestDefinition to be ready. Once data is retrieved and Ready is true it will never again be false.

</details>

</div>

<div class="api-card" id="update-action">
<span id="M:Sansar.Simulation.Objective.Update(System.Action{Sansar.Script.OperationCompleteEvent})"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 36.7.0</span></div>

```csharp signature
public void Update(
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Update the ObjectiveDefinition data.

| Parameter | Type | Description |
|---|---|---|
| `handler` | [Action&lt;Sansar.Script.OperationCompleteEvent&gt;](https://learn.microsoft.com/dotnet/api/system.action-1) | Handler to be called when the event completes. |

<details class="api-remarks"><summary>Remarks</summary>

Use in a WaitFor to wait for the data for the QuestDefinition to be ready. Once data is retrieved and Ready is true it will never again be false.

</details>

</div>


## Used in examples

- [QuestDebugExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/QuestDebugExample.cs)
- [ScriptLibrary/Quest/QuestGiverInteraction.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestGiverInteraction.cs)
- [ScriptLibrary/Quest/QuestGiverTrigger.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestGiverTrigger.cs)
- [ScriptLibrary/Quest/QuestObject.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestObject.cs)
- [ScriptLibrary/Quest/QuestObjectBase.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestObjectBase.cs)
- [ScriptLibrary/Quest/QuestObjectInteraction.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestObjectInteraction.cs)
- [ScriptLibrary/Quest/QuestObjectTrigger.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestObjectTrigger.cs)
- [ScriptLibrary/Quest/QuestVisibility.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestVisibility.cs)

<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>