Skip to content

Get Sansar

Script API

Client

Where: Client
More page actions

For the complete documentation index, see llms.txt. This page is also available as Markdown.

The Client class is used for access to the Client connected to a AgentPrivate.

public class Client : Sansar.Script.InstanceInterface

Remarks

This class is also used for receiving input events from a client.

Members at a glance

KindMembers
PropertiesAgentInfo · InVrAndHandsActive · UI
MethodsCaptureImage · 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

Added in 39.1.0
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

Added in 43.2.1
public void CaptureImage(CameraComponent component)

Take a image from the camera point of view

ParameterTypeDescription
componentCameraComponent

ClearTutorialHint

Added in 32.0.0
public void ClearTutorialHint()

Clears any scripted tutorial hint being shown to the player

Added in 32.0.0
public void ClearTutorialHint(     Action<Sansar.Script.OperationCompleteEvent> handler )

Clears any scripted tutorial hint being shown to the player

ParameterTypeDescription
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.

EnableAutomaticTutorialHints

Added in 32.0.0
public void EnableAutomaticTutorialHints(bool enabled)

Enables / Disables automatic (non-scripted) tutorial hints.

ParameterTypeDescription
enabledboolEnabled state of automatic hints.
Remarks

If the user has disabled hints in the settings menu, enabling them from script will have no effect.

Added in 32.0.0
public void EnableAutomaticTutorialHints(     bool enabled,     Action<Sansar.Script.OperationCompleteEvent> handler )

Enables / Disables automatic (non-scripted) tutorial hints.

ParameterTypeDescription
enabledboolEnabled state of automatic hints.
handlerAction<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

Added in 37.0.0
public CameraComponent GetActiveCamera()

Returns the active camera for this instance.

Returns: CameraComponent — The active camera for this instance

OpenQuestCharacterDialog

Added in 35.1.0
public void OpenQuestCharacterDialog(QuestCharacter character)

Opens the quest dialog for a character.

ParameterTypeDescription
characterQuestCharacterThe character to open the quest dialog for.

OpenStoreListing

public void OpenStoreListing(Guid productId)

Opens the product’s Store page.

ParameterTypeDescription
productIdGuidA product ID from a Sansar store listing.

OpenUserStore

Added in 37.0.0
public void OpenUserStore(string creatorHandle)

Opens the user’s Store page.

ParameterTypeDescription
creatorHandlestringCreator handle: Creator’s handle Sansar store.

ResetCamera

Added in 37.0.0
public void ResetCamera()

Resets the active camera for this Client to the system default

SendChat

Deprecated
[System.Obsolete("Deprecated. Use AgentPrivate.SendChat or AgentPublic.SendChat", false)] public void SendChat(string message)

Sends a String message to the $className$.

ParameterTypeDescription
messagestringThe 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

Added in 37.0.0
public void SetActiveCamera(CameraComponent component)

Sets the active camera for this Client.

ParameterTypeDescription
componentCameraComponentThe camera component to set
Added in 37.0.0
public void SetActiveCamera(     CameraComponent component,     ScriptCameraControlMode controlMode )

Sets the active camera for this Client.

ParameterTypeDescription
componentCameraComponentThe camera component to set
controlModeScriptCameraControlModeThe script camera control mode to set

ShakeCamera

New in 47.10.0
public CameraShakeHandle ShakeCamera(CameraShakeSettings settings)

Shakes this player’s rendered camera, subject to player comfort settings.

ParameterTypeDescription
settingsCameraShakeSettingsSettings 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.

CameraShakeExample.cs
/* 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

Added in 32.0.0
public void ShowTutorialHint(TutorialHint hint)

Show a tutorial hint to the player

ParameterTypeDescription
hintTutorialHintThe hint to show.
Added in 32.0.0
public void ShowTutorialHint(     TutorialHint hint,     Action<Sansar.Script.OperationCompleteEvent> handler )

Show a tutorial hint to the player

ParameterTypeDescription
hintTutorialHintThe hint to show.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.
Added in 36.9.0
public void ShowTutorialHint(TutorialHint hint, int variant)

Show a tutorial hint to the player

ParameterTypeDescription
hintTutorialHintThe hint to show.
variantintOptional variant of the hint to show.
Added in 36.9.0
public void ShowTutorialHint(     TutorialHint hint,     int variant,     Action<Sansar.Script.OperationCompleteEvent> handler )

Show a tutorial hint to the player

ParameterTypeDescription
hintTutorialHintThe hint to show.
variantintOptional variant of the hint to show.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.

StopAllCameraShakes

New in 47.10.0
public void StopAllCameraShakes(float fadeOut)

Stops all shakes from the calling script on this player, including area shakes.

ParameterTypeDescription
fadeOutfloatEnding 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.

ParameterTypeDescription
CommandstringThe command which occurred.
callbackAction<CommandData>Callback which is executed when the event completes.
canceledAction<Sansar.Script.CancelData>Callback which is executed when the subscription is canceled.
persistentboolOptional, 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.

ParameterTypeDescription
CommandstringThe command which occurred.
ActionCommandActionThe action which occurred.
callbackAction<CommandData>Callback which is executed when the event completes.
canceledAction<Sansar.Script.CancelData>Callback which is executed when the subscription is canceled.
persistentboolOptional, set to false to unsubscribe after one event.

Returns: Sansar.Script.IEventSubscription — An IEventSubscription that can be used to cancel the subscription.

SubscribeToTwitch

Added in 38.1.0
public Sansar.Script.IEventSubscription SubscribeToTwitch(     Action<TwitchData> callback,     bool persistent )

Subscribes to Twitch Events.

ParameterTypeDescription
callbackAction<TwitchData>Callback which is executed when the event completes.
persistentboolOptional, set to false to unsubscribe after one event.

Returns: Sansar.Script.IEventSubscription — An IEventSubscription that can be used to cancel the subscription.

Added in 38.1.0
public Sansar.Script.IEventSubscription SubscribeToTwitch(     TwitchEventType EventType,     Action<TwitchData> callback,     bool persistent )

Subscribes to Twitch Events.

ParameterTypeDescription
EventTypeTwitchEventTypeThe event which occurred
callbackAction<TwitchData>Callback which is executed when the event completes.
persistentboolOptional, set to false to unsubscribe after one event.

Returns: Sansar.Script.IEventSubscription — An IEventSubscription that can be used to cancel the subscription.

TeleportTo

Added in 39.0.0
public void TeleportTo(string spawnPointName)

Teleports to a spawn point in the scene

ParameterTypeDescription
spawnPointNamestringThe 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

ParameterTypeDescription
positionSansar.VectorThe teleport destination position.
forwardSansar.VectorThe 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

Added in 37.1.0
public void TeleportToCharacterEditor()

Teleports to the Character Editor

Remarks

Teleports may be throttled.

Added in 37.1.0
public void TeleportToCharacterEditor(string returnSpawnPointName)

Teleports to the Character Editor

ParameterTypeDescription
returnSpawnPointNamestringWhen 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.

ParameterTypeDescription
avatarIdstringThe SceneInfo.AvatarId of the destination creator.
locationHandlestringThe SceneInfo.LocationHandle of the destination.
Remarks

Teleports may be throttled.

Added in 37.0.0
public void TeleportToLocation(     string avatarId,     string locationHandle,     string spawnPointName )

Teleports the personaHandle to the locationHandle.

ParameterTypeDescription
avatarIdstringThe SceneInfo.AvatarId of the destination creator.
locationHandlestringThe SceneInfo.LocationHandle of the destination.
spawnPointNamestringThe name of the target spawn point in the destination.
Remarks

Teleports may be throttled.

TeleportToLookbook

Added in 37.1.0
public void TeleportToLookbook()

Teleports to the Lookbook

Remarks

Teleports may be throttled.

Added in 37.1.0
public void TeleportToLookbook(string returnSpawnPointName)

Teleports to the Lookbook

ParameterTypeDescription
returnSpawnPointNamestringWhen 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

ParameterTypeDescription
sansarUristringThe 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.

ParameterTypeDescription
typeControlPointTypeSee ControlPointType
intensityfloatIntensity of vibration. Intensity will be clamped to the range [0, 1].
durationfloatDuration of the pulse in milliseconds. Will be clamped to the range [0, 1000].

Used in examples

…and 13 more examples in the snapshot.

Generated from the Sansar 47.10.0 client ScriptApi snapshot.