Skip to content

Get Sansar

Script API

ScenePrivate

Where: Client
More page actions

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

Interface for Scripts that are part of a Scene. A more complete and less limited API than ScenePublic

public class ScenePrivate : Sansar.Script.InstanceInterface

Remarks

The ScenePrivate class provides services relating to the Scene.

Members at a glance

KindMembers
FieldsGravityMaximum · GravityMinimum · MaximumCastRayResults · MinimumCastRadius
PropertiesAgentCount · Chat · DefaultGravity · HttpClient · Reactions · SceneInfo · User
MethodsAddToSceneLibrary · AddToSceneLibraryForAgent · CastBox · CastCapsule · CastRay · CastSphere · ClearAllowFlightOverrideForAgent New in 47.10.0 · ClearAllowFlightOverrides New in 47.10.0 · ClearColorLut New in 47.10.0 · ClearColorLutOverrideForAgent New in 47.10.0 · ClearColorLutOverrides New in 47.10.0 · ClearSceneLibrary · ClearSceneLibraryForAgent · CreateCluster · CreateDataStore · FindAgent · FindObject · FindReflective · FindScript · GetAgent · GetAgents · GetAllowFlight New in 47.10.0 · GetBoxClosestPoints · GetCapsuleClosestPoints · GetGravity · GetPortalCreatorName · GetPortalDescription · GetPortalUri · GetSphereClosestPoints · GetTimeOfDay New in 47.10.0 · GetTimeOfDayMode New in 47.10.0 · OverrideAudioStream · OverrideIndexedMediaSource · OverrideMediaSource · PerformIndexedMediaAction · PerformMediaAction · PlaySound · PlaySoundAtPosition · PlayStream · PlayStreamAtPosition · RemoveFromSceneLibrary · RemoveFromSceneLibraryForAgent · ResetScene · SetAllowFlight New in 47.10.0 · SetColorLut New in 47.10.0 · SetGravity · SetMegaphone · SetTimeOfDay New in 47.10.0 · SetTimeOfDayMode New in 47.10.0 · ShakeCameraAtPosition New in 47.10.0 · StopAllCameraShakes New in 47.10.0 · ToString · VoiceBroadcastStart · VoiceBroadcastStop · VoiceBroadcastStopAll

Fields

GravityMaximum

public static readonly float GravityMaximum

The maximum gravity magnitude in m/s^2, which is equal to 49.05 or 5 G’s.

Remarks

A value greater than this will clamp to this value.

GravityMinimum

public static readonly float GravityMinimum

The minimum allowed gravity magnitude in m/s^2, which is equal to zero.

Remarks

A value less than this will clamp to this value.

MaximumCastRayResults

public static readonly int MaximumCastRayResults

The maximum number of results returned from a CastRay, CastSphere or CastBox call. Anything over this will be truncated.

MinimumCastRadius

public static readonly float MinimumCastRadius

The minimum radius for a CastSphere call or minimum half extents for CastBox. Any value smaller than this will use CastRay instead.

Properties

AgentCount

public uint AgentCount { get; }

The number of agents in the Scene.

Value: uint — Unsigned integer count of the number of agents in the Scene.

Remarks

This number changes when agents join and part.

Chat

public Chat Chat { get; }

Gets the Chat interface for this Scene

Value: Chat — The Chat Api

DefaultGravity

public float DefaultGravity { get; }

The default gravity magnitude in the scene in m/s^2, which is equal to 9.81 or 1 G.

Value: float — The default scene gravity magnitude.

Remarks

The direction of the gravity vector is constant.

Example
float sansarGravity = ScenePrivate.DefaultGravity; // Get default gravity in m/s^2

HttpClient

public HttpClient HttpClient { get; }

Gets the HttpClient for this Scene

Value: HttpClient — The HttpClient Api

Reactions

Added in 41.0.0
public Reactions Reactions { get; }

Gets the Reactions interface for this Scene

Value: Reactions — The Chat Api

SceneInfo

public SceneInfo SceneInfo { get; }

Gets the SceneInfo for this Scene

Value: SceneInfo — The full SceneInfo Api

User

public User User { get; }

Gets the User interface for this Scene

Value: User — The User Api

Methods

AddToSceneLibrary

Added in 47.1.1
public void AddToSceneLibrary(     ClusterResource resource,     string displayName )

Add an item to the scene library for all users.

ParameterTypeDescription
resourceClusterResourceThe cluster resource to add.
displayNamestringThe display name shown in the backpack.
Added in 47.2.0
public void AddToSceneLibrary(     ClusterResource resource,     string displayName,     string thumbnailAssetId )

Add an item to the scene library for all users.

ParameterTypeDescription
resourceClusterResourceThe cluster resource to add.
displayNamestringThe display name shown in the backpack.
thumbnailAssetIdstringOptional thumbnail asset id shown as the item icon.

AddToSceneLibraryForAgent

Added in 47.1.1
public void AddToSceneLibraryForAgent(     AgentPrivate agent,     ClusterResource resource,     string displayName )

Add an item to the scene library for a specific agent.

ParameterTypeDescription
agentAgentPrivateThe target agent.
resourceClusterResourceThe cluster resource to add.
displayNamestringThe display name shown in the backpack.
Added in 47.2.0
public void AddToSceneLibraryForAgent(     AgentPrivate agent,     ClusterResource resource,     string displayName,     string thumbnailAssetId )

Add an item to the scene library for a specific agent.

ParameterTypeDescription
agentAgentPrivateThe target agent.
resourceClusterResourceThe cluster resource to add.
displayNamestringThe display name shown in the backpack.
thumbnailAssetIdstringOptional thumbnail asset id shown as the item icon.

CastBox

public RayCastHit[] CastBox(     Sansar.Vector halfExtents,     Sansar.Vector start,     Sansar.Vector end )

Casts a box from start to end and returns an array of collisions along the path.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.

Returns: RayCastHit[]

Remarks

If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.

public RayCastHit[] CastBox(     Sansar.Vector halfExtents,     Sansar.Quaternion orientation,     Sansar.Vector start,     Sansar.Vector end )

Casts a box from start to end and returns an array of collisions along the path.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
orientationSansar.QuaternionThe orientation of the query shape.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.

Returns: RayCastHit[]

Remarks

If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.

public RayCastHit[] CastBox(     Sansar.Vector halfExtents,     Sansar.Vector start,     Sansar.Vector end,     int maxHits )

Casts a box from start to end and returns an array of collisions along the path.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

Remarks

If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.

public RayCastHit[] CastBox(     Sansar.Vector halfExtents,     Sansar.Quaternion orientation,     Sansar.Vector start,     Sansar.Vector end,     int maxHits )

Casts a box from start to end and returns an array of collisions along the path.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
orientationSansar.QuaternionThe orientation of the query shape.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

Remarks

If all 3 dimensions are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.

CastCapsule

public RayCastHit[] CastCapsule(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Vector start,     Sansar.Vector end )

Casts a capsule from start to end and returns an array of collisions along the path.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.

Returns: RayCastHit[]

Remarks

If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.

public RayCastHit[] CastCapsule(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Quaternion orientation,     Sansar.Vector start,     Sansar.Vector end )

Casts a capsule from start to end and returns an array of collisions along the path.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
orientationSansar.QuaternionThe orientation of the query shape.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.

Returns: RayCastHit[]

Remarks

If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.

public RayCastHit[] CastCapsule(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Vector start,     Sansar.Vector end,     int maxHits )

Casts a capsule from start to end and returns an array of collisions along the path.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

Remarks

If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.

public RayCastHit[] CastCapsule(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Quaternion orientation,     Sansar.Vector start,     Sansar.Vector end,     int maxHits )

Casts a capsule from start to end and returns an array of collisions along the path.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
orientationSansar.QuaternionThe orientation of the query shape.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

Remarks

If the radius and capsule length are less than ScenePrivate.MinimumCastRadius the call will be forwarded to CastRay instead.

CastRay

public RayCastHit[] CastRay(Sansar.Vector start, Sansar.Vector end)

Casts a ray from start to end and returns an array of collisions along the path.

ParameterTypeDescription
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.

Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.

Remarks

maxHits defaults to 1 if unspecified and will return only the nearest hit.

public RayCastHit[] CastRay(     Sansar.Vector start,     Sansar.Vector end,     int maxHits )

Casts a ray from start to end and returns an array of collisions along the path.

ParameterTypeDescription
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.

Remarks

maxHits defaults to 1 if unspecified and will return only the nearest hit.

CastSphere

public RayCastHit[] CastSphere(     float radius,     Sansar.Vector start,     Sansar.Vector end )

Casts a sphere from start to end and returns an array of collisions along the path.

ParameterTypeDescription
radiusfloatThe radius of the sphere.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.

Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.

Remarks

If the radius is less than ScenePrivate.MinimumCastRadius the call will be forwarded to ScenePrivate.CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.

public RayCastHit[] CastSphere(     float radius,     Sansar.Vector start,     Sansar.Vector end,     int maxHits )

Casts a sphere from start to end and returns an array of collisions along the path.

ParameterTypeDescription
radiusfloatThe radius of the sphere.
startSansar.VectorThe initial point of the query.
endSansar.VectorThe end point of the query.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.

Remarks

If the radius is less than ScenePrivate.MinimumCastRadius the call will be forwarded to ScenePrivate.CastRay instead. maxHits defaults to 1 if unspecified and will return only the nearest hit.

ClearAllowFlightOverrideForAgent

New in 47.10.0
public void ClearAllowFlightOverrideForAgent(AgentPrivate agent)

Clears the per-agent flight override for a specific agent.

ParameterTypeDescription
agentAgentPrivateThe target agent.
Remarks

The agent will inherit this instance’s default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.

New in 47.10.0
public void ClearAllowFlightOverrideForAgent(     AgentPrivate agent,     Action<Sansar.Script.OperationCompleteEvent> handler )

Clears the per-agent flight override for a specific agent.

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

The agent will inherit this instance’s default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.

ClearAllowFlightOverrides

New in 47.10.0
public void ClearAllowFlightOverrides()

Clears all per-agent flight overrides in this scene.

Remarks

All agents will inherit this instance’s unchanged default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

New in 47.10.0
public void ClearAllowFlightOverrides(     Action<Sansar.Script.OperationCompleteEvent> handler )

Clears all per-agent flight overrides in this scene.

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

All agents will inherit this instance’s unchanged default. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

ClearColorLut

New in 47.10.0
public void ClearColorLut()

Removes the scene-wide color LUT override, going back to the LUT chosen in the scene settings.

Remarks

Per-agent overrides persist until cleared or the agent leaves. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

New in 47.10.0
public void ClearColorLut(     Action<Sansar.Script.OperationCompleteEvent> handler )

Removes the scene-wide color LUT override, going back to the LUT chosen in the scene settings.

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

Per-agent overrides persist until cleared or the agent leaves. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

ClearColorLutOverrideForAgent

New in 47.10.0
public void ClearColorLutOverrideForAgent(AgentPrivate agent)

Clears the per-agent color LUT override for a specific agent.

ParameterTypeDescription
agentAgentPrivateThe target agent.
Remarks

The agent goes back to the scene-wide LUT. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.

New in 47.10.0
public void ClearColorLutOverrideForAgent(     AgentPrivate agent,     Action<Sansar.Script.OperationCompleteEvent> handler )

Clears the per-agent color LUT override for a specific agent.

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

The agent goes back to the scene-wide LUT. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued the client update, not client acknowledgment; it fails if the agent has left.

ClearColorLutOverrides

New in 47.10.0
public void ClearColorLutOverrides()

Clears all per-agent color LUT overrides in this scene.

Remarks

All agents go back to the scene-wide LUT, which is left as it is. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

New in 47.10.0
public void ClearColorLutOverrides(     Action<Sansar.Script.OperationCompleteEvent> handler )

Clears all per-agent color LUT overrides in this scene.

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

All agents go back to the scene-wide LUT, which is left as it is. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

ClearSceneLibrary

Added in 47.1.1
public void ClearSceneLibrary()

Remove all items from the scene library for all users.

ClearSceneLibraryForAgent

Added in 47.1.1
public void ClearSceneLibraryForAgent(AgentPrivate agent)

Remove all per-agent scene library items for a specific agent.

ParameterTypeDescription
agentAgentPrivateThe target agent.

CreateCluster

public ulong CreateCluster(     ClusterResource asset,     Sansar.Vector position,     Sansar.Quaternion rotation,     Sansar.Vector initialVelocity )

Creates a new cluster and adds it to the Scene.

ParameterTypeDescription
assetClusterResourceAsset identifier to create.
positionSansar.VectorMono.Simd.Vector4f for the initial position.
rotationSansar.QuaternionMono.Simd.Vector4f for the initial rotation.
initialVelocitySansar.VectorMono.Simd.Vector4f for the initial velocity.

Returns: ulong — The internal event id for the completion event.

Remarks

The new object may start simulating before the event is triggered.

Deprecated
[System.Obsolete("Deprecated. Use the Action<> overload", false)] public ulong CreateCluster(     ClusterResource asset,     Sansar.Vector position,     Sansar.Quaternion rotation,     Sansar.Vector initialVelocity,     ScenePrivate.CreateClusterHandler handler )

Creates a new cluster and adds it to the Scene.

ParameterTypeDescription
assetClusterResourceAsset identifier to create.
positionSansar.VectorMono.Simd.Vector4f for the initial position.
rotationSansar.QuaternionMono.Simd.Vector4f for the initial rotation.
initialVelocitySansar.VectorMono.Simd.Vector4f for the initial velocity.
handlerScenePrivate.CreateClusterHandlerHandler to be called when the event completes.

Returns: ulong — The internal event id for the completion event.

Remarks

The new object may start simulating before the event is triggered.

public void CreateCluster(     ClusterResource asset,     Sansar.Vector position,     Sansar.Quaternion rotation,     Sansar.Vector initialVelocity,     Action<ScenePrivate.CreateClusterData> handler )

Creates a new cluster and adds it to the Scene.

ParameterTypeDescription
assetClusterResourceAsset identifier to create.
positionSansar.VectorMono.Simd.Vector4f for the initial position.
rotationSansar.QuaternionMono.Simd.Vector4f for the initial rotation.
initialVelocitySansar.VectorMono.Simd.Vector4f for the initial velocity.
handlerAction<ScenePrivate.CreateClusterData>Handler to be called when the event completes.
Remarks

The new object may start simulating before the event is triggered.

CreateDataStore

Added in 37.1.0
public DataStore CreateDataStore(Guid id)

Returns a new instance of the DataStore class.

ParameterTypeDescription
idGuidThe id of the DataStore to create.

Returns: DataStore — A new DataStore object.

Remarks

All DataStore objects with a given DataStore.Id share the same database.

Added in 37.1.0
public DataStore CreateDataStore(string id)

Returns a new instance of the DataStore class.

ParameterTypeDescription
idstringString used to generate an id. If the id is a valid Guid then it will be used directly.

Returns: DataStore — A new DataStore object.

Remarks

All DataStore objects with a given DataStore.Id share the same database. Ensure that this value is kept secret and unique.

FindAgent

public AgentPrivate FindAgent(Sansar.Script.ObjectId objectId)

Looks up an Agent associated with the given object id.

ParameterTypeDescription
objectIdSansar.Script.ObjectIdThe object to find.

Returns: AgentPrivate — The agent, or null if an agent cannot be found with that id.

Remarks

Agents may leave at any time.

public AgentPrivate FindAgent(Sansar.Script.SessionId sessionId)

Looks up an Agent associated with the given session id if they are in the scene.

ParameterTypeDescription
sessionIdSansar.Script.SessionIdThe session id of the agent to find.

Returns: AgentPrivate — The agent, or null if an agent cannot be found with that id in the scene.

Remarks

Agents may leave at any time. Attempting to use an Agent or AgentInfo interface for an agent no longer in the scene will throw a NullReferenceException.

public AgentPrivate FindAgent(Guid personaId)

Looks up an Agent associated with the given persona id, if they are in the scene.

ParameterTypeDescription
personaIdGuidThe object to find.

Returns: AgentPrivate — The agent, or null if an agent cannot be found with that id in the scene.

Remarks

Agents may leave at any time. Attempting to use an Agent or AgentInfo interface for an agent no longer in the scene will throw a NullReferenceException.

FindObject

public ObjectPrivate FindObject(Sansar.Script.ObjectId objectId)

Looks up a Object associated with the given object id.

ParameterTypeDescription
objectIdSansar.Script.ObjectIdThe object to find.

Returns: ObjectPrivate — The ObjectPrivate, or null if a Object cannot be found with that id.

FindReflective

[Sansar.Script.NonReflective] public IEnumerable<TInterface> FindReflective<TInterface>(     string name ) where TInterface : class

Looks up Reflective objects in the scene that match the interface type by class name.

ParameterTypeDescription
namestringThe type name of the object’s class to find.

Type parameters: TInterface: The interface type to find.

Returns: IEnumerable<TInterface> — An IEnumerable which contains all objects of the given type name that match the given interface.

Remarks

The name given corresponds to the Type.FullName of the object. Multiple scripts may define unrelated types of the same name, but only registered objects that match the interface of TInterface will be returned.

FindScript

public object FindScript(Sansar.Script.ScriptId scriptId)

Looks up the script object associated with the given scriptId

ParameterTypeDescription
scriptIdSansar.Script.ScriptIdThe scriptId of the object to find.

Returns: object — The script object, or null if an script cannot be found with that id in the scene.

Remarks

Objects and their associated scripts may be removed the scene at any time.

GetAgent

public AgentPrivate GetAgent(uint index)

Get an AgentPrivate for a specific agent in the Scene.

ParameterTypeDescription
indexuintThe index of the agent to get.

Returns: AgentPrivate — Returns null if the index is larger than the number of agents in the Scene, or if the agent is not fully loaded.

Remarks

Agents may appear at different indices as they join and part.

GetAgents

public IEnumerable<AgentPrivate> GetAgents()

Returns the current list of Agents in the Scene.

Returns: IEnumerable<AgentPrivate> — The current list of agents in the Scene

GetAllowFlight

New in 47.10.0
public bool GetAllowFlight()

Gets the flight availability default for this scene instance.

Returns: bool — The instance default, before per-agent overrides.

Remarks

Flight settings are per instance: they are not saved to the world or shared with clone regions.

GetBoxClosestPoints

public RayCastHit[] GetBoxClosestPoints(     Sansar.Vector halfExtents,     Sansar.Vector origin,     float maximumDistance )

Extends a box with the given half extents the maximum distance and returns any hits.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
originSansar.VectorThe center of the query.
maximumDistancefloatthe maximum distance from the origin to check.

Returns: RayCastHit[]

public RayCastHit[] GetBoxClosestPoints(     Sansar.Vector halfExtents,     Sansar.Vector origin,     Sansar.Quaternion orientation,     float maximumDistance )

Extends a box with the given half extents the maximum distance and returns any hits.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
originSansar.VectorThe center of the query.
orientationSansar.QuaternionThe orientation of the query shape.
maximumDistancefloatthe maximum distance from the origin to check.

Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.

public RayCastHit[] GetBoxClosestPoints(     Sansar.Vector halfExtents,     Sansar.Vector origin,     float maximumDistance,     int maxHits )

Extends a box with the given half extents the maximum distance and returns any hits.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
originSansar.VectorThe center of the query.
maximumDistancefloatthe maximum distance from the origin to check.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

public RayCastHit[] GetBoxClosestPoints(     Sansar.Vector halfExtents,     Sansar.Vector origin,     Sansar.Quaternion orientation,     float maximumDistance,     int maxHits )

Extends a box with the given half extents the maximum distance and returns any hits.

ParameterTypeDescription
halfExtentsSansar.VectorThe x,y,z distance from the center of the box to the corresponding face.
originSansar.VectorThe center of the query.
orientationSansar.QuaternionThe orientation of the query shape.
maximumDistancefloatthe maximum distance from the origin to check.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[] — An array of hit results, ordered from nearest to furthest. If the cast did not hit anything the array will be empty.

GetCapsuleClosestPoints

public RayCastHit[] GetCapsuleClosestPoints(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Vector origin,     float maximumDistance )

Extends a capsule with the given parameters the maximum distance and returns any hits.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
originSansar.VectorThe base of the capsule.
maximumDistancefloatthe maximum distance from the origin to check.

Returns: RayCastHit[]

public RayCastHit[] GetCapsuleClosestPoints(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Vector origin,     Sansar.Quaternion orientation,     float maximumDistance )

Extends a capsule with the given parameters the maximum distance and returns any hits.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
originSansar.VectorThe base of the capsule.
orientationSansar.QuaternionThe orientation of the query shape.
maximumDistancefloatthe maximum distance from the origin to check.

Returns: RayCastHit[]

public RayCastHit[] GetCapsuleClosestPoints(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Vector origin,     float maximumDistance,     int maxHits )

Extends a capsule with the given parameters the maximum distance and returns any hits.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
originSansar.VectorThe base of the capsule.
maximumDistancefloatthe maximum distance from the origin to check.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

public RayCastHit[] GetCapsuleClosestPoints(     Sansar.Vector capsuleStart,     Sansar.Vector capsuleEnd,     float capsuleRadius,     Sansar.Vector origin,     Sansar.Quaternion orientation,     float maximumDistance,     int maxHits )

Extends a capsule with the given parameters the maximum distance and returns any hits.

ParameterTypeDescription
capsuleStartSansar.VectorThe base point of the capsule.
capsuleEndSansar.VectorThe end point of the capsule.
capsuleRadiusfloatThe radius of the capsule to query.
originSansar.VectorThe base of the capsule.
orientationSansar.QuaternionThe orientation of the query shape.
maximumDistancefloatthe maximum distance from the origin to check.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

GetGravity

public float GetGravity()

Gets the scene’s current acceleration of gravity in m/s^2.

Returns: float — Number indicating the magnitude of gravity in the scene.

Remarks

The default gravity for the scene is ScenePrivate.DefaultGravity

Example
float currentGravity = ScenePrivate.GetGravity(); // Get the current scene gravity in m/s^2

GetPortalCreatorName

public string GetPortalCreatorName(Sansar.Script.ObjectId objectId)

The name of the user who created the specified portal.

ParameterTypeDescription
objectIdSansar.Script.ObjectId

Returns: string — String

Remarks

User who created the portal.

GetPortalDescription

public string GetPortalDescription(Sansar.Script.ObjectId objectId)

Description for the specified portal.

ParameterTypeDescription
objectIdSansar.Script.ObjectId

Returns: string — String

Remarks

The description of the portal.

GetPortalUri

public string GetPortalUri(Sansar.Script.ObjectId objectId)

URI destination for the specified portal.

ParameterTypeDescription
objectIdSansar.Script.ObjectId

Returns: string — String

Remarks

The URI of the destination of the portal.

GetSphereClosestPoints

public RayCastHit[] GetSphereClosestPoints(     float radius,     Sansar.Vector origin,     float maximumDistance )

Extends a sphere with the given radius the maximum distance and returns any hits.

ParameterTypeDescription
radiusfloatThe radius of the sphere to query.
originSansar.VectorThe center of the query.
maximumDistancefloatthe maximum distance from the origin to check.

Returns: RayCastHit[]

public RayCastHit[] GetSphereClosestPoints(     float radius,     Sansar.Vector origin,     float maximumDistance,     int maxHits )

Extends a sphere with the given radius the maximum distance and returns any hits.

ParameterTypeDescription
radiusfloatThe radius of the sphere to query.
originSansar.VectorThe center of the query.
maximumDistancefloatthe maximum distance from the origin to check.
maxHitsintLimit the number of results returned.

Returns: RayCastHit[]

GetTimeOfDay

New in 47.10.0
public float GetTimeOfDay()

Gets the scene’s current time of day in hours.

Returns: float — The time of day in hours, from 0 up to 24.

Remarks

The scene clock runs from 0 at midnight up to 24, so 13.5 is half past one in the afternoon. With the mode TimeOfDayMode.Off this is the time set in the scene settings, which has no effect on the scene until the mode is TimeOfDayMode.Fixed or TimeOfDayMode.Cycle.

Example
float hours = ScenePrivate.GetTimeOfDay(); // Get the scene clock in hours

GetTimeOfDayMode

New in 47.10.0
public TimeOfDayMode GetTimeOfDayMode()

Gets how the scene’s time of day runs.

Returns: TimeOfDayMode — The current TimeOfDayMode.

Remarks

See TimeOfDayExample.cs in the Examples folder for more details.

Example
bool dayNight = ScenePrivate.GetTimeOfDayMode() != TimeOfDayMode.Off; // Is the time of day in effect?

OverrideAudioStream

public void OverrideAudioStream(string url)

Overrides source of web audio streams.

ParameterTypeDescription
urlstringURL to use.
Remarks

Applies to all agents in this scene. NOTE: this may cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.

public void OverrideAudioStream(     string url,     Action<Sansar.Script.OperationCompleteEvent> handler )

Overrides source of web audio streams.

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

Applies to all agents in this scene. NOTE: this may cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.

OverrideIndexedMediaSource

Added in 46.5.0
public void OverrideIndexedMediaSource(     string url,     int mediaIndex,     int mediaWidth,     int mediaHeight,     Action<Sansar.Script.OperationCompleteEvent> handler )

Overrides source of indexed media surfaces.

ParameterTypeDescription
urlstringURL to use.
mediaIndexint(cMediaChannel only) source index.
mediaWidthint(cMediaChannel only) source width.
mediaHeightint(cMediaChannel only) source height.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.
Remarks

Applies to all agents in this scene. NOTE: this will cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.

OverrideMediaSource

public void OverrideMediaSource(string url)

Sets stream channel source.

ParameterTypeDescription
urlstringURL to use.
public void OverrideMediaSource(     string url,     int mediaWidth,     int mediaHeight )

Overrides source of media surfaces.

ParameterTypeDescription
urlstringURL to use.
mediaWidthint(cMediaChannel only) source width.
mediaHeightint(cMediaChannel only) source height.
Remarks

Applies to all agents in this scene. NOTE: this will cause a few seconds of silence while restarting starting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.

public void OverrideMediaSource(     string url,     int mediaWidth,     int mediaHeight,     Action<Sansar.Script.OperationCompleteEvent> handler )

Overrides source of media surfaces.

ParameterTypeDescription
urlstringURL to use.
mediaWidthint(cMediaChannel only) source width.
mediaHeightint(cMediaChannel only) source height.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.
Remarks

Applies to all agents in this scene. NOTE: this will cause a few seconds of silence while restarting the stream. To avoid silence, assign URLs in your SceneSettings instead, which will pre-load them.

PerformIndexedMediaAction

Added in 46.5.0
public void PerformIndexedMediaAction(     MediaAction action,     int mediaIndex,     Action<Sansar.Script.OperationCompleteEvent> handler )

Performs a specific action on the current media surface index.

ParameterTypeDescription
actionMediaActionThe action to perform.
mediaIndexint(cMediaChannel only) source index.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.
Remarks

Applies to all agents currently in the scene.

PerformMediaAction

public void PerformMediaAction(MediaAction action)

Performs a specific action on the current media surface.

ParameterTypeDescription
actionMediaActionThe action to perform.
Remarks

Applies to this agent only.

public void PerformMediaAction(     MediaAction action,     Action<Sansar.Script.OperationCompleteEvent> handler )

Performs a specific action on the current media surface.

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

Applies to all agents currently in the scene.

PlaySound

public PlayHandle PlaySound(     SoundResource soundResource,     PlaySettings playSettings )

Play sound to direct output.

ParameterTypeDescription
soundResourceSoundResourceThe sound resource to play.
playSettingsPlaySettingsThe play parameters.

Returns: PlayHandle — The play handle for controlling playback.

Remarks

Plays for all agents in this scene.

PlaySoundAtPosition

public PlayHandle PlaySoundAtPosition(     SoundResource soundResource,     Sansar.Vector position,     PlaySettings playSettings )

Play sound at specified position.

ParameterTypeDescription
soundResourceSoundResourceThe sound resource to play.
positionSansar.VectorThe absolute position.
playSettingsPlaySettingsThe play parameters.

Returns: PlayHandle — The play handle for controlling playback.

Remarks

Plays for all agents in this scene. By setting an absolute position, the location of this sound will be static. If you want the sound to move, you must play the sound on an audio component and move the audio component.

PlayStream

public PlayHandle PlayStream(     StreamChannel streamChannel,     float loudness )

Play web audio stream to direct output.

ParameterTypeDescription
streamChannelStreamChannelChannel of the audio stream to play.
loudnessfloatRelative loudness in dB.

Returns: PlayHandle — The play handle for controlling playback.

Remarks

Plays for all agents in this scene.

PlayStreamAtPosition

public PlayHandle PlayStreamAtPosition(     StreamChannel streamChannel,     Sansar.Vector position,     float loudness )

Play web audio stream at specified position.

ParameterTypeDescription
streamChannelStreamChannelChannel of the audio stream to play.
positionSansar.VectorThe absolute position.
loudnessfloatRelative loudness in dB.

Returns: PlayHandle — The play handle for controlling playback.

Remarks

Plays for all agents in this scene. By setting an absolute position, the location of this sound will be static. If you want the sound to move, you must play the sound on an audio component and move the audio component.

RemoveFromSceneLibrary

Added in 47.1.1
public void RemoveFromSceneLibrary(ClusterResource resource)

Remove an item from the scene library for all users.

ParameterTypeDescription
resourceClusterResourceThe cluster resource to remove.

RemoveFromSceneLibraryForAgent

Added in 47.1.1
public void RemoveFromSceneLibraryForAgent(     AgentPrivate agent,     ClusterResource resource )

Remove an item from the scene library for a specific agent.

ParameterTypeDescription
agentAgentPrivateThe target agent.
resourceClusterResourceThe cluster resource to remove.

ResetScene

[Sansar.Script.Interface(Restricted=true)] public void ResetScene()

Restarts the Scene.

Remarks

All clients will be momentarily disconnected.

SetAllowFlight

New in 47.10.0
public void SetAllowFlight(bool allowFlight)

Sets the flight availability default for this scene instance.

ParameterTypeDescription
allowFlightboolThe default for agents without an explicit override.
Remarks

Existing overrides persist until cleared or the agent leaves. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

New in 47.10.0
public void SetAllowFlight(     bool allowFlight,     Action<Sansar.Script.OperationCompleteEvent> handler )

Sets the flight availability default for this scene instance.

ParameterTypeDescription
allowFlightboolThe default for agents without an explicit override.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.
Remarks

Existing overrides persist until cleared or the agent leaves. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

SetColorLut

New in 47.10.0
public void SetColorLut(TextureResource lut)

Overrides the scene’s color LUT for everyone in this scene instance.

ParameterTypeDescription
lutTextureResourceThe LUT texture to grade with, or null to go back to the LUT chosen in the scene settings.
Remarks

Every user without a per-agent override, see AgentPrivate.SetColorLut, is graded with this LUT in place of the scene settings LUT, including users who join later. A PostFX volume with its own LUT still takes over while a user’s camera is inside it. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

New in 47.10.0
public void SetColorLut(     TextureResource lut,     Action<Sansar.Script.OperationCompleteEvent> handler )

Overrides the scene’s color LUT for everyone in this scene instance.

ParameterTypeDescription
lutTextureResourceThe LUT texture to grade with, or null to go back to the LUT chosen in the scene settings.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.
Remarks

Every user without a per-agent override, see AgentPrivate.SetColorLut, is graded with this LUT in place of the scene settings LUT, including users who join later. A PostFX volume with its own LUT still takes over while a user’s camera is inside it. This instance-only setting is not saved to the world or shared with clone regions. The write is queued for the next world update. The callback, or ScriptBase.WaitFor in a coroutine, reports whether the server committed the change and queued client updates, not client acknowledgment.

SetGravity

public void SetGravity(float scale)

Sets the scene’s current gravity acceleration in m/s^2.

ParameterTypeDescription
scalefloatThe gravity magnitude.
Remarks

Set to ScenePrivate.DefaultGravity to return to the default. The valid range is from ScenePrivate.GravityMinimum to ScenePrivate.GravityMaximum. The direction cannot be changed.

Example
ScenePrivate.SetGravity(1.622f); // Set the scene to moon gravity
Deprecated
[System.Obsolete("Deprecated. Use the Action<> overload", false)] public ulong SetGravity(     float scale,     Sansar.Script.ScriptBase.OperationComplete handler )

Sets the scene’s current gravity acceleration in m/s^2.

ParameterTypeDescription
scalefloatThe gravity magnitude.
handlerSansar.Script.ScriptBase.OperationCompleteHandler to be called when the event completes.

Returns: ulong — The return value is an internal event id which can be passed to ScriptBase.WaitFor from a coroutine for synchronous behavior.

Remarks

Set to ScenePrivate.DefaultGravity to return to the default. The valid range is from ScenePrivate.GravityMinimum to ScenePrivate.GravityMaximum. The direction cannot be changed.

Example
ScenePrivate.SetGravity(1.622f); // Set the scene to moon gravity
public void SetGravity(     float scale,     Action<Sansar.Script.OperationCompleteEvent> handler )

Sets the scene’s current gravity acceleration in m/s^2.

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

Set to ScenePrivate.DefaultGravity to return to the default. The valid range is from ScenePrivate.GravityMinimum to ScenePrivate.GravityMaximum. The direction cannot be changed.

Example
ScenePrivate.SetGravity(1.622f); // Set the scene to moon gravity

SetMegaphone

public void SetMegaphone(AgentPrivate agent, bool enable)

Sets the megaphone status of the user.

ParameterTypeDescription
agentAgentPrivateAgent to broadcast.
enableboolIf true, user’s voice will be heard by everyone in the scene. If false, user’s voice will be spatialized normally.
public void SetMegaphone(     AgentPrivate agent,     bool enable,     Action<Sansar.Script.OperationCompleteEvent> handler )

Sets the megaphone status of the user.

ParameterTypeDescription
agentAgentPrivateAgent to broadcast.
enableboolIf true, user’s voice will be heard by everyone in the scene. If false, user’s voice will be spatialized normally.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.

SetTimeOfDay

New in 47.10.0
public void SetTimeOfDay(float hours)

Sets the scene’s current time of day in hours.

ParameterTypeDescription
hoursfloatThe time of day in hours, from 0 at midnight up to 24. 18.5 is half past six in the evening.
Remarks

Every user in the scene sees the change. With the mode TimeOfDayMode.Cycle the clock carries on running from the new time. The mode is left as it is: the time only takes effect while the mode is TimeOfDayMode.Fixed or TimeOfDayMode.Cycle, see ScenePrivate.SetTimeOfDayMode.

Example
ScenePrivate.SetTimeOfDay(18.5f); // Half past six in the evening
New in 47.10.0
public void SetTimeOfDay(     float hours,     Action<Sansar.Script.OperationCompleteEvent> handler )

Sets the scene’s current time of day in hours.

ParameterTypeDescription
hoursfloatThe time of day in hours, from 0 at midnight up to 24. 18.5 is half past six in the evening.
handlerAction<Sansar.Script.OperationCompleteEvent>Handler to be called when the event completes.
Remarks

Every user in the scene sees the change. With the mode TimeOfDayMode.Cycle the clock carries on running from the new time. The mode is left as it is: the time only takes effect while the mode is TimeOfDayMode.Fixed or TimeOfDayMode.Cycle, see ScenePrivate.SetTimeOfDayMode.

Example
ScenePrivate.SetTimeOfDay(18.5f); // Half past six in the evening

SetTimeOfDayMode

New in 47.10.0
public void SetTimeOfDayMode(TimeOfDayMode mode)

Sets how the scene’s time of day runs.

ParameterTypeDescription
modeTimeOfDayModeThe new mode.
Remarks

Every user in the scene sees the change. The clock carries on from its current reading: switching from TimeOfDayMode.Cycle to TimeOfDayMode.Fixed holds the sun where it is, and switching back sets it moving again from there. A scene built with the mode TimeOfDayMode.Off has its sun baked into the lighting, so the bounced sunlight stays as built when a script turns the time of day on; build the scene with the mode TimeOfDayMode.Fixed or TimeOfDayMode.Cycle for the full effect.

Example
ScenePrivate.SetTimeOfDayMode(TimeOfDayMode.Cycle); // Start the day and night cycle
New in 47.10.0
public void SetTimeOfDayMode(     TimeOfDayMode mode,     Action<Sansar.Script.OperationCompleteEvent> handler )

Sets how the scene’s time of day runs.

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

Every user in the scene sees the change. The clock carries on from its current reading: switching from TimeOfDayMode.Cycle to TimeOfDayMode.Fixed holds the sun where it is, and switching back sets it moving again from there. A scene built with the mode TimeOfDayMode.Off has its sun baked into the lighting, so the bounced sunlight stays as built when a script turns the time of day on; build the scene with the mode TimeOfDayMode.Fixed or TimeOfDayMode.Cycle for the full effect.

Example
ScenePrivate.SetTimeOfDayMode(TimeOfDayMode.Cycle); // Start the day and night cycle

ShakeCameraAtPosition

New in 47.10.0
public CameraShakeHandle ShakeCameraAtPosition(     Sansar.Vector position,     float radius,     CameraShakeSettings settings )

Requests a shake for current players, attenuated by camera distance from a world position.

ParameterTypeDescription
positionSansar.VectorStationary world-space source position in meters; W is ignored.
radiusfloatWorld-space radius in meters, clamped to 0 through 1000; 0 is inert.
settingsCameraShakeSettingsSettings to snapshot, or null for fresh default settings.

Returns: CameraShakeHandle — A non-null handle for this script’s request, including inert requests.

Remarks

Strength falls to zero at the radius using each player’s unshaken viewing camera. Only players present at the call receive it. Direction remains in camera space. Player comfort settings and VR limits can reduce or suppress any shake. Leaving the world ends that player’s shake. Only the rendered view changes; camera transforms, audio and targeting are unaffected.

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.

StopAllCameraShakes

New in 47.10.0
public void StopAllCameraShakes(float fadeOut)

Stops all shakes from the calling script on current players in this scene.

ParameterTypeDescription
fadeOutfloatEnding fade in seconds, clamped to 0 through 5; defaults to 0.1.
Remarks

0 stops immediately. Shakes from other scripts are unaffected.

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.

VoiceBroadcastStart

Deprecated
[System.Obsolete("Deprecated. use ScenePrivate.SetMegaphone(agent, true) instead", false)] public void VoiceBroadcastStart(AgentPrivate agent)

Start broadcasting agent’s voice to the voice broadcast channel.

ParameterTypeDescription
agentAgentPrivateAgent to broadcast.
Remarks

Plays for all agents in this scene.

VoiceBroadcastStop

Deprecated
[System.Obsolete("Deprecated. use ScenePrivate.SetMegaphone(agent, false) instead", false)] public void VoiceBroadcastStop(AgentPrivate agent)

Stop broadcasting agent’s voice to voice broadcast channel.

ParameterTypeDescription
agentAgentPrivateAgent to stop broadcasting.
Remarks

Stops for all agents in this scene.

VoiceBroadcastStopAll

Deprecated
[System.Obsolete("Deprecated. use AgentPrivate.SetMegaphone(false) instead", false)] public void VoiceBroadcastStopAll()

Stop broadcasting all voices to voice broadcast channel.

Remarks

Stops for all agents in this scene.

Used in examples

…and 56 more examples in the snapshot.

Generated from the Sansar 47.10.0 client ScriptApi snapshot.