# User

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.User"></span>

The User class handles interactions user logins and logoffs.

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

## Members at a glance

| Kind | Members |
|---|---|
| **Fields** | [AddUser](#adduser) · [RemoveUser](#removeuser) |
| **Methods** | [Subscribe](#subscribe) |

## Fields

### AddUser

<div class="api-card">
<span id="F:Sansar.Simulation.User.AddUser"></span>

```csharp signature
public static readonly string AddUser
```

For subscribing to events for users entering the scene

</div>

### RemoveUser

<div class="api-card">
<span id="F:Sansar.Simulation.User.RemoveUser"></span>

```csharp signature
public static readonly string RemoveUser
```

For subscribing to events for users leaving the scene

</div>


## Methods

### Subscribe

<div class="api-card" id="subscribe-string-subscriptionhandler-boolean">
<span id="M:Sansar.Simulation.User.Subscribe(System.String,Sansar.Simulation.User.SubscriptionHandler,System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Simulation.UserData>", false)]
public void Subscribe(
    string Action,
    User.SubscriptionHandler callback,
    bool persistent
)
```

Subscribes to User Events.

| Parameter | Type | Description |
|---|---|---|
| `Action` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string action of the event: AddUser, RemoveUser |
| `callback` | [User.SubscriptionHandler](/scripting/api/sansar.simulation/user.subscriptionhandler) | 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. |

</div>

<div class="api-card" id="subscribe-string-action-boolean">
<span id="M:Sansar.Simulation.User.Subscribe(System.String,System.Action{Sansar.Simulation.UserData},System.Boolean)"></span>

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

Subscribes to User Events.

| Parameter | Type | Description |
|---|---|---|
| `Action` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string action of the event: AddUser, RemoveUser |
| `callback` | [Action&lt;UserData&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>

<div class="api-card" id="subscribe-string-sessionid-subscriptionhandler-boolean">
<span id="M:Sansar.Simulation.User.Subscribe(System.String,Sansar.Script.SessionId,Sansar.Simulation.User.SubscriptionHandler,System.Boolean)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Use subscription callbacks of type Action<Sansar.Simulation.UserData>", false)]
public void Subscribe(
    string Action,
    Sansar.Script.SessionId User,
    User.SubscriptionHandler callback,
    bool persistent
)
```

Subscribes to User Events.

| Parameter | Type | Description |
|---|---|---|
| `Action` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string action of the event: AddUser, RemoveUser |
| `User` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId for the user. |
| `callback` | [User.SubscriptionHandler](/scripting/api/sansar.simulation/user.subscriptionhandler) | 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. |

</div>

<div class="api-card" id="subscribe-string-sessionid-action-boolean">
<span id="M:Sansar.Simulation.User.Subscribe(System.String,Sansar.Script.SessionId,System.Action{Sansar.Simulation.UserData},System.Boolean)"></span>

```csharp signature
public Sansar.Script.IEventSubscription Subscribe(
    string Action,
    Sansar.Script.SessionId User,
    Action<UserData> callback,
    bool persistent
)
```

Subscribes to User Events.

| Parameter | Type | Description |
|---|---|---|
| `Action` | [string](https://learn.microsoft.com/dotnet/api/system.string) | string action of the event: AddUser, RemoveUser |
| `User` | [Sansar.Script.SessionId](/scripting/api/sansar.script/sessionid) | Sansar.Script.SessionId for the user. |
| `callback` | [Action&lt;UserData&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

- [StatsExample.cs](/scripting/examples/stats-example)
- [TeleportHotkeys.cs](/scripting/examples/teleport-hotkeys)
- [VisitorTrackerExample.cs](/scripting/examples/visitor-tracker)
- [BanHammerExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/BanHammerExample.cs)
- [BroadcastUsers.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/BroadcastUsers.cs)
- `CameraShakeExample.cs`
- [CastRayExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/CastRayExample.cs)
- [CommandExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/CommandExample.cs)
- [CommandScreenshot.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/CommandScreenshot.cs)
- [CoroutineEventExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/CoroutineEventExample.cs)
- [CoroutineExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/CoroutineExample.cs)
- [EventExample.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/EventExample.cs)

…and 14 more examples in the snapshot.

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