The Client class is used for access to the Client connected to a AgentPrivate.
public class Client : Sansar.Script.InstanceInterfaceRemarks
This class is also used for receiving input events from a client.
Members at a glance
| Kind | Members |
|---|---|
| Properties | AgentInfo · InVrAndHandsActive · UI |
| Methods | CaptureImage · ClearTutorialHint · EnableAutomaticTutorialHints · GetActiveCamera · OpenQuestCharacterDialog · OpenStoreListing · OpenUserStore · ResetCamera · SendChat · SetActiveCamera · ShakeCamera New in 47.10.0 · ShowTutorialHint · StopAllCameraShakes New in 47.10.0 · SubscribeToCommand · SubscribeToTwitch · TeleportTo · TeleportToCharacterEditor · TeleportToLocation · TeleportToLookbook · TeleportToUri · ToString · VibrationPulse |
Properties
AgentInfo
public AgentInfo AgentInfo { get; }Returns the AgentInfo for this instance.
Value: AgentInfo — The AgentInfo for this instance
Remarks
The AgentInfo holds information about an agent.
InVrAndHandsActive
public bool InVrAndHandsActive { get; }Retrieves whether or not this Client is using a VR headset and using hand tracking controllers currently.
Value: bool — Whether or not this Client is using a VR headset and using hand tracking controllers currently.
UI
public UI UI { get; }Returns the UI for this instance.
Value: UI — The UI for this instance
Remarks
The UI for this instance.
Methods
CaptureImage
public void CaptureImage(CameraComponent component)Take a image from the camera point of view
| Parameter | Type | Description |
|---|---|---|
component | CameraComponent |
ClearTutorialHint
public void ClearTutorialHint()Clears any scripted tutorial hint being shown to the player
public void ClearTutorialHint(
Action<Sansar.Script.OperationCompleteEvent> handler
)Clears any scripted tutorial hint being shown to the player
| Parameter | Type | Description |
|---|---|---|
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
EnableAutomaticTutorialHints
public void EnableAutomaticTutorialHints(bool enabled)Enables / Disables automatic (non-scripted) tutorial hints.
| Parameter | Type | Description |
|---|---|---|
enabled | bool | Enabled state of automatic hints. |
Remarks
If the user has disabled hints in the settings menu, enabling them from script will have no effect.
public void EnableAutomaticTutorialHints(
bool enabled,
Action<Sansar.Script.OperationCompleteEvent> handler
)Enables / Disables automatic (non-scripted) tutorial hints.
| Parameter | Type | Description |
|---|---|---|
enabled | bool | Enabled state of automatic hints. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
Remarks
If the user has disabled hints in the settings menu, enabling them from script will have no effect.
GetActiveCamera
public CameraComponent GetActiveCamera()Returns the active camera for this instance.
Returns: CameraComponent — The active camera for this instance
OpenQuestCharacterDialog
public void OpenQuestCharacterDialog(QuestCharacter character)Opens the quest dialog for a character.
| Parameter | Type | Description |
|---|---|---|
character | QuestCharacter | The character to open the quest dialog for. |
OpenStoreListing
public void OpenStoreListing(Guid productId)Opens the product’s Store page.
| Parameter | Type | Description |
|---|---|---|
productId | Guid | A product ID from a Sansar store listing. |
OpenUserStore
public void OpenUserStore(string creatorHandle)Opens the user’s Store page.
| Parameter | Type | Description |
|---|---|---|
creatorHandle | string | Creator handle: Creator’s handle Sansar store. |
ResetCamera
public void ResetCamera()Resets the active camera for this Client to the system default
SendChat
[System.Obsolete("Deprecated. Use AgentPrivate.SendChat or AgentPublic.SendChat", false)]
public void SendChat(string message)Sends a String message to the $className$.
| Parameter | Type | Description |
|---|---|---|
message | string | The message to send. |
Throws NullReferenceException: If the user is no longer online.
Throws ThrottleException: If the throttle rate is exceeded.
Remarks
eprecated. Use AgentPrivate.SendChat or AgentPublic.SendChat
SetActiveCamera
public void SetActiveCamera(CameraComponent component)Sets the active camera for this Client.
| Parameter | Type | Description |
|---|---|---|
component | CameraComponent | The camera component to set |
public void SetActiveCamera(
CameraComponent component,
ScriptCameraControlMode controlMode
)Sets the active camera for this Client.
| Parameter | Type | Description |
|---|---|---|
component | CameraComponent | The camera component to set |
controlMode | ScriptCameraControlMode | The script camera control mode to set |
ShakeCamera
public CameraShakeHandle ShakeCamera(CameraShakeSettings settings)Shakes this player’s rendered camera, subject to player comfort settings.
| Parameter | Type | Description |
|---|---|---|
settings | CameraShakeSettings | Settings to snapshot, or null for fresh default settings. |
Returns: CameraShakeHandle — A non-null handle for this script’s request, including inert requests.
Remarks
Only the rendered view changes; camera transforms, audio and targeting are unaffected. Player comfort settings and VR limits can reduce or suppress any shake. Leaving the world ends it.
/* This example is licensed under the Creative Commons Attribution 4.0 International License. * Copyright 2026 Sansar, Inc. https://creativecommons.org/licenses/by/4.0/ */
using System;using System.Collections.Generic;using Sansar;using Sansar.Script;using Sansar.Simulation;
/// <summary>Demonstrates camera shake with chat commands on the default channel.</summary>/// <remarks>Use /shake rumble, jitter, sway, impact, near, engine or stop./// Engine toggles a continuous rumble for the sender; stop clears this script's shakes for everyone./// An optional CameraComponent on this object fixes the view for current and future users./// Player comfort settings and VR limits can reduce or suppress the motion.</remarks>public class CameraShakeExample : SceneObjectScript{ private CameraComponent camera; private readonly Dictionary<SessionId, CameraShakeHandle> engines = new Dictionary<SessionId, CameraShakeHandle>();
/// <summary>Sets up chat commands and the optional fixed camera.</summary> public override void Init() { ObjectPrivate.TryGetFirstComponent(out camera); ScenePrivate.User.Subscribe(User.AddUser, OnUserAdded); ScenePrivate.User.Subscribe(User.RemoveUser, OnUserRemoved); ScenePrivate.Chat.Subscribe(Chat.DefaultChannel, OnChat, true);
// Script reloads also need to set up users who are already in the world. foreach (AgentPrivate agent in ScenePrivate.GetAgents()) { SetCamera(agent); }
// The Debug local-source live test requires this marker from the real body. Log.Write("CameraShakeExample ready (real shake body): /shake rumble, jitter, sway, impact, near, engine, stop"); }
private void SetCamera(AgentPrivate agent) { if (camera != null && agent != null && agent.IsValid) { agent.Client.SetActiveCamera(camera, ScriptCameraControlMode.AgentControlOnly); } }
private void OnUserAdded(UserData data) { SetCamera(ScenePrivate.FindAgent(data.User)); }
private void OnUserRemoved(UserData data) { // Leaving the world ends that player's shake; discard the old session's handle. engines.Remove(data.User); }
private bool StopEngine(SessionId sessionId) { CameraShakeHandle engine; if (!engines.TryGetValue(sessionId, out engine)) { return false; }
engine.Stop(0.25f); engines.Remove(sessionId); return true; }
private void OnChat(ChatData data) { string[] words = data.Message.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words.Length != 2 || !words[0].Equals("/shake", StringComparison.OrdinalIgnoreCase)) { return; }
// SourceId identifies the sender, rather than the object running this script. AgentPrivate agent = ScenePrivate.FindAgent(data.SourceId); if (agent == null || !agent.IsValid) { return; } SessionId sessionId = agent.AgentInfo.SessionId;
switch (words[1].ToLowerInvariant()) { case "rumble": // Presets are mutable: edit before starting. Starts snapshot the settings. CameraShakeSettings rumble = CameraShakeSettings.Earthquake(); rumble.Direction = new Vector(1, 0.5f, 0); agent.Client.ShakeCamera(rumble); break;
case "jitter": agent.Client.ShakeCamera(new CameraShakeSettings { Pattern = CameraShakePattern.Jitter, Magnitude = 0.25f, Duration = 1.0f // Frequency 0 uses Jitter's default of 20 Hz. }); break;
case "sway": // Long side-to-side motion for the fixed-camera pixel-displacement test. agent.Client.ShakeCamera(new CameraShakeSettings { Pattern = CameraShakePattern.Sway, Magnitude = 0.6f, Frequency = 2.0f, Duration = 6.0f, Direction = new Vector(1, 0, 0), FadeOut = 0.3f }); break;
case "impact": // Landing: one downward kick. Duration 0 would still give just one kick. agent.Client.ShakeCamera(CameraShakeSettings.Impact(new Vector(0, -1, 0))); break;
case "near": // Only players present now receive this explosion. Their camera distance // from this object's world position controls falloff to zero at 20 meters. ScenePrivate.ShakeCameraAtPosition(ObjectPrivate.Position, 20.0f, CameraShakeSettings.Explosion()); break;
case "engine": // Send again to stop; separate sessions retain separate handles. if (!StopEngine(sessionId)) { engines[sessionId] = agent.Client.ShakeCamera(CameraShakeSettings.EngineRumble()); } break;
case "stop": StopEngine(sessionId); // Both stop-all scopes affect only shakes requested by this script. agent.Client.StopAllCameraShakes(); ScenePrivate.StopAllCameraShakes(); engines.Clear(); break; } }}Source: Examples/CameraShakeExample.cs in the Sansar 47.10.0 client ScriptApi snapshot.
ShowTutorialHint
public void ShowTutorialHint(TutorialHint hint)Show a tutorial hint to the player
| Parameter | Type | Description |
|---|---|---|
hint | TutorialHint | The hint to show. |
public void ShowTutorialHint(
TutorialHint hint,
Action<Sansar.Script.OperationCompleteEvent> handler
)Show a tutorial hint to the player
| Parameter | Type | Description |
|---|---|---|
hint | TutorialHint | The hint to show. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
public void ShowTutorialHint(TutorialHint hint, int variant)Show a tutorial hint to the player
| Parameter | Type | Description |
|---|---|---|
hint | TutorialHint | The hint to show. |
variant | int | Optional variant of the hint to show. |
public void ShowTutorialHint(
TutorialHint hint,
int variant,
Action<Sansar.Script.OperationCompleteEvent> handler
)Show a tutorial hint to the player
| Parameter | Type | Description |
|---|---|---|
hint | TutorialHint | The hint to show. |
variant | int | Optional variant of the hint to show. |
handler | Action<Sansar.Script.OperationCompleteEvent> | Handler to be called when the event completes. |
StopAllCameraShakes
public void StopAllCameraShakes(float fadeOut)Stops all shakes from the calling script on this player, including area shakes.
| Parameter | Type | Description |
|---|---|---|
fadeOut | float | Ending fade in seconds, clamped to 0 through 5; defaults to 0.1. |
Remarks
0 stops immediately. Shakes from other scripts are unaffected.
SubscribeToCommand
public Sansar.Script.IEventSubscription SubscribeToCommand(
string Command,
Action<CommandData> callback,
Action<Sansar.Script.CancelData> canceled,
bool persistent
)Subscribes to Command Events.
| Parameter | Type | Description |
|---|---|---|
Command | string | The command which occurred. |
callback | Action<CommandData> | Callback which is executed when the event completes. |
canceled | Action<Sansar.Script.CancelData> | Callback which is executed when the subscription is canceled. |
persistent | bool | Optional, set to false to unsubscribe after one event. |
Returns: Sansar.Script.IEventSubscription — An IEventSubscription that can be used to cancel the subscription.
public Sansar.Script.IEventSubscription SubscribeToCommand(
string Command,
CommandAction Action,
Action<CommandData> callback,
Action<Sansar.Script.CancelData> canceled,
bool persistent
)Subscribes to Command Events.
| Parameter | Type | Description |
|---|---|---|
Command | string | The command which occurred. |
Action | CommandAction | The action which occurred. |
callback | Action<CommandData> | Callback which is executed when the event completes. |
canceled | Action<Sansar.Script.CancelData> | Callback which is executed when the subscription is canceled. |
persistent | bool | Optional, set to false to unsubscribe after one event. |
Returns: Sansar.Script.IEventSubscription — An IEventSubscription that can be used to cancel the subscription.
SubscribeToTwitch
public Sansar.Script.IEventSubscription SubscribeToTwitch(
Action<TwitchData> callback,
bool persistent
)Subscribes to Twitch Events.
| Parameter | Type | Description |
|---|---|---|
callback | Action<TwitchData> | Callback which is executed when the event completes. |
persistent | bool | Optional, set to false to unsubscribe after one event. |
Returns: Sansar.Script.IEventSubscription — An IEventSubscription that can be used to cancel the subscription.
public Sansar.Script.IEventSubscription SubscribeToTwitch(
TwitchEventType EventType,
Action<TwitchData> callback,
bool persistent
)Subscribes to Twitch Events.
| Parameter | Type | Description |
|---|---|---|
EventType | TwitchEventType | The event which occurred |
callback | Action<TwitchData> | Callback which is executed when the event completes. |
persistent | bool | Optional, set to false to unsubscribe after one event. |
Returns: Sansar.Script.IEventSubscription — An IEventSubscription that can be used to cancel the subscription.
TeleportTo
public void TeleportTo(string spawnPointName)Teleports to a spawn point in the scene
| Parameter | Type | Description |
|---|---|---|
spawnPointName | string | The name of the target spawn point in the destination. |
Remarks
Teleports may be throttled.
public void TeleportTo(Sansar.Vector position, Sansar.Vector forward)Teleports to the position facing the specified direction
| Parameter | Type | Description |
|---|---|---|
position | Sansar.Vector | The teleport destination position. |
forward | Sansar.Vector | The teleport destination forward direction. |
Remarks
The agent will be set to the specified position facing the given forward direction. Note that avatars always remain upright so the Z component of the forward vector will be ignored.
TeleportToCharacterEditor
public void TeleportToCharacterEditor()Teleports to the Character Editor
Remarks
Teleports may be throttled.
public void TeleportToCharacterEditor(string returnSpawnPointName)Teleports to the Character Editor
| Parameter | Type | Description |
|---|---|---|
returnSpawnPointName | string | When returning to the world from the character editor, this spawn point will be used |
Remarks
Teleports may be throttled.
TeleportToLocation
public void TeleportToLocation(string avatarId, string locationHandle)Teleports the personaHandle to the locationHandle.
| Parameter | Type | Description |
|---|---|---|
avatarId | string | The SceneInfo.AvatarId of the destination creator. |
locationHandle | string | The SceneInfo.LocationHandle of the destination. |
Remarks
Teleports may be throttled.
public void TeleportToLocation(
string avatarId,
string locationHandle,
string spawnPointName
)Teleports the personaHandle to the locationHandle.
| Parameter | Type | Description |
|---|---|---|
avatarId | string | The SceneInfo.AvatarId of the destination creator. |
locationHandle | string | The SceneInfo.LocationHandle of the destination. |
spawnPointName | string | The name of the target spawn point in the destination. |
Remarks
Teleports may be throttled.
TeleportToLookbook
public void TeleportToLookbook()Teleports to the Lookbook
Remarks
Teleports may be throttled.
public void TeleportToLookbook(string returnSpawnPointName)Teleports to the Lookbook
| Parameter | Type | Description |
|---|---|---|
returnSpawnPointName | string | When returning to the world from the lookbook, this spawn point will be used |
Remarks
Teleports may be throttled.
TeleportToUri
public void TeleportToUri(string sansarUri)Teleports to the specified URI
| Parameter | Type | Description |
|---|---|---|
sansarUri | string | The URI to teleport to. |
Remarks
Teleports may be throttled.
ToString
public override string ToString()A string representation of this object.
Returns: string — A string representation of this object.
Remarks
The format of this string may change between releases.
VibrationPulse
public void VibrationPulse(
ControlPointType type,
float intensity,
float duration
)Pulses the vibration haptic motor for a control point.
| Parameter | Type | Description |
|---|---|---|
type | ControlPointType | See ControlPointType |
intensity | float | Intensity of vibration. Intensity will be clamped to the range [0, 1]. |
duration | float | Duration of the pulse in milliseconds. Will be clamped to the range [0, 1000]. |
Used in examples
- MoverExample1.cs
- StatsExample.cs
- TeleportHotkeys.cs
- VisitorTrackerExample.cs
- BanHammerExample.cs
CameraShakeExample.cs- CastRayExample.cs
- CommandExample.cs
- CommandScreenshot.cs
- InteractionScreenshot.cs
- PewPewExample.cs
- ScriptLibrary/Quest/QuestObjectBase.cs
…and 13 more examples in the snapshot.
Generated from the Sansar 47.10.0 client ScriptApi snapshot.