# AgentScript

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/scriptbase">Sansar.Script.ScriptBase</a></span>
</div>

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

Extend AgentScript to create a script to be attached directly to an agent. For future use: Sansar does not currently support adding scripts to agents.

```csharp
public abstract class AgentScript : Sansar.Script.ScriptBase
```

## Remarks

Override [`ScriptBase.Init`](/scripting/api/sansar.script/scriptbase#init) for script initialization, primarily event subscriptions.



Use [`AgentScript.ObjectPrivate`](/scripting/api/sansar.simulation/agentscript#objectprivate) to access the ObjectPrivate the object that represents the Agent.



Use [`AgentScript.ScenePublic`](/scripting/api/sansar.simulation/agentscript#scenepublic) to access the a limited API for the Scene the agent is in.



Use [`AgentScript.AgentPrivate`](/scripting/api/sansar.simulation/agentscript#agentprivate) to access the Agent the object is attached to.

## Members at a glance

| Kind | Members |
|---|---|
| **Constructors** | [AgentScript](#agentscript) |
| **Properties** | [AgentPrivate](#agentprivate) · [ObjectPrivate](#objectprivate) · [ScenePublic](#scenepublic) |

## Constructors

### AgentScript

<div class="api-card">
<span id="M:Sansar.Simulation.AgentScript.#ctor"></span>
<span id="C:Sansar.Simulation.AgentScript()"></span>

```csharp signature
protected AgentScript()
```

This constructor is called before any properties have been set. Override [`ScriptBase.Init`](/scripting/api/sansar.script/scriptbase#init) to initialize the script after properties have been set.

</div>


## Properties

### AgentPrivate

<div class="api-card">
<span id="P:Sansar.Simulation.AgentScript.AgentPrivate"></span>

```csharp signature
[Sansar.Script.NonReflective]
public AgentPrivate AgentPrivate { protected get; set; }
```

The Agent API for the agent this script is attached to.

**Value:** [AgentPrivate](/scripting/api/sansar.simulation/agentprivate) — The Agent this script is attached to if the script is on an avatar, null otherwise.

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

The Agent will be set before [`ScriptBase.Init`](/scripting/api/sansar.script/scriptbase#init)  is called.

</details>

</div>

### ObjectPrivate

<div class="api-card">
<span id="P:Sansar.Simulation.AgentScript.ObjectPrivate"></span>

```csharp signature
[Sansar.Script.NonReflective]
public ObjectPrivate ObjectPrivate { protected get; set; }
```

The ObjectPrivate this script is attached to if it is attached to an object.

**Value:** [ObjectPrivate](/scripting/api/sansar.simulation/objectprivate) — The scene object this script is attached to if it is attached to an object, null otherwise.

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

For AgentScripts this is the Agent&#39;s ObjectPrivate of their avatar.

</details>

</div>

### ScenePublic

<div class="api-card">
<span id="P:Sansar.Simulation.AgentScript.ScenePublic"></span>

```csharp signature
[Sansar.Script.NonReflective]
public ScenePublic ScenePublic { protected get; set; }
```

Basic scene information for the current scene.

**Value:** [ScenePublic](/scripting/api/sansar.simulation/scenepublic) — The Scene this object is in.

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

This value will be set before Init is called.

</details>

</div>


## Used in examples

- [StatsExample.cs](/scripting/examples/stats-example)

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