# Interaction

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>
</div>

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



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

## Members at a glance

| Kind | Members |
|---|---|
| **Methods** | [GetEnabled](#getenabled) · [GetPrompt](#getprompt) · [SetEnabled](#setenabled) · [SetPrompt](#setprompt) · [Subscribe](#subscribe) |

## Methods

### GetEnabled

<div class="api-card">
<span id="M:Sansar.Simulation.Interaction.GetEnabled"></span>
<span id="M:Sansar.Simulation.Interaction.GetEnabled()"></span>

```csharp signature
public bool GetEnabled()
```

Returns true if the interaction is enabled.

**Returns:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean) — true if the interaction is enabled.

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

Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;.

</details>

</div>

### GetPrompt

<div class="api-card">
<span id="M:Sansar.Simulation.Interaction.GetPrompt"></span>
<span id="M:Sansar.Simulation.Interaction.GetPrompt()"></span>

```csharp signature
public string GetPrompt()
```

Get the current Interaction prompt.

**Returns:** [string](https://learn.microsoft.com/dotnet/api/system.string) — The current prompt string.

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

The prompt text shows when hovering over the object the script is on.

</details>

</div>

### SetEnabled

<div class="api-card" id="setenabled-boolean">
<span id="M:Sansar.Simulation.Interaction.SetEnabled(System.Boolean)"></span>

```csharp signature
public void SetEnabled(bool value)
```

Change an Interaction state to disabled or enabled.

| Parameter | Type | Description |
|---|---|---|
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true to enable the Interaction, false to disable it. |

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

All Interactions start off enabled. Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;.

</details>

</div>

<div class="api-card" id="setenabled-sessionid-boolean">
<span id="M:Sansar.Simulation.Interaction.SetEnabled(Sansar.Script.SessionId,System.Boolean)"></span>

```csharp signature
public void SetEnabled(Sansar.Script.SessionId sessionId, bool value)
```

Change an Interaction state to disabled or enabled.

| Parameter | Type | Description |
|---|---|---|
| `sessionId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | The SessionId of the agent to disable or enable the interaction for.. |
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true to enable the Interaction, false to disable it. |

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

All Interactions start off enabled. Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;. This method will only change the enabled state for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setEnabled calls.

</details>

</div>

<div class="api-card" id="setenabled-agentprivate-boolean">
<span id="M:Sansar.Simulation.Interaction.SetEnabled(Sansar.Simulation.AgentPrivate,System.Boolean)"></span>

```csharp signature
public void SetEnabled(AgentPrivate agent, bool value)
```

Change an Interaction state to disabled or enabled.

| Parameter | Type | Description |
|---|---|---|
| `agent` | [AgentPrivate](/scripting/api/sansar.simulation/agentprivate) | The agent to disable or enable the interaction for. |
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true to enable the Interaction, false to disable it. |

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

All Interactions start off enabled. Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;. This method will only change the enabled state for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setEnabled calls.

</details>

</div>

<div class="api-card" id="setenabled-boolean-operationcomplete">
<span id="M:Sansar.Simulation.Interaction.SetEnabled(System.Boolean,Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong SetEnabled(
    bool value,
    Sansar.Script.ScriptBase.OperationComplete handler
)
```

Change an Interaction state to disabled or enabled.

| Parameter | Type | Description |
|---|---|---|
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true to enable the Interaction, false to disable it. |
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — A legacy eventId

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

All Interactions start off enabled. Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;.

</details>

</div>

<div class="api-card" id="setenabled-boolean-action">
<span id="M:Sansar.Simulation.Interaction.SetEnabled(System.Boolean,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetEnabled(
    bool value,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Change an Interaction state to disabled or enabled.

| Parameter | Type | Description |
|---|---|---|
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true to enable the Interaction, false to disable it. |
| `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>

All Interactions start off enabled. Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;.

</details>

</div>

<div class="api-card" id="setenabled-sessionid-boolean-action">
<span id="M:Sansar.Simulation.Interaction.SetEnabled(Sansar.Script.SessionId,System.Boolean,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetEnabled(
    Sansar.Script.SessionId sessionId,
    bool value,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Change an Interaction state to disabled or enabled.

| Parameter | Type | Description |
|---|---|---|
| `sessionId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | The SessionId of the agent to disable or enable the interaction for.. |
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true to enable the Interaction, false to disable it. |
| `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>

All Interactions start off enabled. Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;. This method will only change the enabled state for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setEnabled calls.

</details>

</div>

<div class="api-card" id="setenabled-agentprivate-boolean-action">
<span id="M:Sansar.Simulation.Interaction.SetEnabled(Sansar.Simulation.AgentPrivate,System.Boolean,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetEnabled(
    AgentPrivate agent,
    bool value,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Change an Interaction state to disabled or enabled.

| Parameter | Type | Description |
|---|---|---|
| `agent` | [AgentPrivate](/scripting/api/sansar.simulation/agentprivate) | The agent to disable or enable the interaction for. |
| `value` | [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | true to enable the Interaction, false to disable it. |
| `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>

All Interactions start off enabled. Disabled interactions do not highlight, do not show their prompt and cannot be &#39;clicked&#39;. This method will only change the enabled state for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setEnabled calls.

</details>

</div>

### SetPrompt

<div class="api-card" id="setprompt-string">
<span id="M:Sansar.Simulation.Interaction.SetPrompt(System.String)"></span>

```csharp signature
public void SetPrompt(string prompt)
```

Set the Interaction prompt string.

| Parameter | Type | Description |
|---|---|---|
| `prompt` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The string to set the prompt to. |

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

The prompt text shows when hovering over the object the script is on. The prompt must be 128 characters or less and 4 lines or less. Use [`DefaultValueAttribute`](/scripting/api/sansar.script/defaultvalueattribute) to set a default prompt.

</details>

</div>

<div class="api-card" id="setprompt-sessionid-string">
<span id="M:Sansar.Simulation.Interaction.SetPrompt(Sansar.Script.SessionId,System.String)"></span>

```csharp signature
public void SetPrompt(
    Sansar.Script.SessionId sessionId,
    string prompt
)
```

Set the Interaction prompt string.

| Parameter | Type | Description |
|---|---|---|
| `sessionId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | The sessionId of the user to change the prompt for. |
| `prompt` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The string to set the prompt to. |

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

The prompt text shows when hovering over the object the script is on. The prompt must be 128 characters or less and 4 lines or less. Will only change the prompt for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setPrompt calls.

</details>

</div>

<div class="api-card" id="setprompt-agentprivate-string">
<span id="M:Sansar.Simulation.Interaction.SetPrompt(Sansar.Simulation.AgentPrivate,System.String)"></span>

```csharp signature
public void SetPrompt(AgentPrivate agent, string prompt)
```

Set the Interaction prompt string.

| Parameter | Type | Description |
|---|---|---|
| `agent` | [AgentPrivate](/scripting/api/sansar.simulation/agentprivate) | The agent to change the prompt for. |
| `prompt` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The string to set the prompt to. |

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

The prompt text shows when hovering over the object the script is on. The prompt must be 128 characters or less and 4 lines or less. Will only change the prompt for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setPrompt calls.

</details>

</div>

<div class="api-card" id="setprompt-string-operationcomplete">
<span id="M:Sansar.Simulation.Interaction.SetPrompt(System.String,Sansar.Script.ScriptBase.OperationComplete)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Deprecated. Use the Action<> overload", false)]
public ulong SetPrompt(
    string prompt,
    Sansar.Script.ScriptBase.OperationComplete handler
)
```

Set the Interaction prompt string.

| Parameter | Type | Description |
|---|---|---|
| `prompt` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The string to set the prompt to. |
| `handler` | [Sansar.Script.ScriptBase.OperationComplete](/scripting/api/sansar.script/scriptbase.operationcomplete) | Handler to be called when the event completes. |

**Returns:** [ulong](https://learn.microsoft.com/dotnet/api/system.uint64) — A legacy eventId

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

The prompt text shows when hovering over the object the script is on. The prompt must be 128 characters or less and 4 lines or less. Use [`DefaultValueAttribute`](/scripting/api/sansar.script/defaultvalueattribute) to set a default prompt.

</details>

</div>

<div class="api-card" id="setprompt-string-action">
<span id="M:Sansar.Simulation.Interaction.SetPrompt(System.String,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetPrompt(
    string prompt,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Set the Interaction prompt string.

| Parameter | Type | Description |
|---|---|---|
| `prompt` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The string to set the prompt 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>

The prompt text shows when hovering over the object the script is on. The prompt must be 128 characters or less and 4 lines or less. Use [`DefaultValueAttribute`](/scripting/api/sansar.script/defaultvalueattribute) to set a default prompt.

</details>

</div>

<div class="api-card" id="setprompt-sessionid-string-action">
<span id="M:Sansar.Simulation.Interaction.SetPrompt(Sansar.Script.SessionId,System.String,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetPrompt(
    Sansar.Script.SessionId sessionId,
    string prompt,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Set the Interaction prompt string.

| Parameter | Type | Description |
|---|---|---|
| `sessionId` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | The sessionId of the user to change the prompt for. |
| `prompt` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The string to set the prompt 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>

The prompt text shows when hovering over the object the script is on. The prompt must be 128 characters or less and 4 lines or less. Will only change the prompt for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setPrompt calls.

</details>

</div>

<div class="api-card" id="setprompt-agentprivate-string-action">
<span id="M:Sansar.Simulation.Interaction.SetPrompt(Sansar.Simulation.AgentPrivate,System.String,System.Action{Sansar.Script.OperationCompleteEvent})"></span>

```csharp signature
public void SetPrompt(
    AgentPrivate agent,
    string prompt,
    Action<Sansar.Script.OperationCompleteEvent> handler
)
```

Set the Interaction prompt string.

| Parameter | Type | Description |
|---|---|---|
| `agent` | [AgentPrivate](/scripting/api/sansar.simulation/agentprivate) | The agent to change the prompt for. |
| `prompt` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The string to set the prompt 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>

The prompt text shows when hovering over the object the script is on. The prompt must be 128 characters or less and 4 lines or less. Will only change the prompt for a single user and will not persist across client restarts, server restarts, or leaving the scene (even for changing avatars). It will also be overriden by any global setPrompt calls.

</details>

</div>

### Subscribe

<div class="api-card">
<span id="M:Sansar.Simulation.Interaction.Subscribe(System.Action{Sansar.Simulation.InteractionData},System.Boolean)"></span>

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

Subscribes to Interaction Events.

| Parameter | Type | Description |
|---|---|---|
| `callback` | [Action&lt;InteractionData&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>


## Used in examples

- [MoverExample1.cs](/scripting/examples/mover-examples)
- [MoverExample3.cs](/scripting/examples/mover-examples)
- [InteractionExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/InteractionExample.cs)
- [InteractionScreenshot.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/InteractionScreenshot.cs)
- [MyScripts/HelloWorld.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/MyScripts/HelloWorld.cs)
- [ScriptLibrary/Quest/QuestCharacter.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestCharacter.cs)
- [ScriptLibrary/Quest/QuestGiver.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestGiver.cs)
- [ScriptLibrary/Quest/QuestGiverInteraction.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestGiverInteraction.cs)
- [ScriptLibrary/Quest/QuestObject.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestObject.cs)
- [ScriptLibrary/Quest/QuestObjectInteraction.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestObjectInteraction.cs)
- [ScriptLibrary/Scene/HintText.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/HintText.cs)
- [ScriptLibrary/Scene/Interaction.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/Interaction.cs)

…and 1 more examples in the snapshot.

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