ScriptAPI reference

API Reference

A compact reference for the public and protected ScriptAPI surface available to scripts derived from ScriptBase.

ScriptAPI / Reference

Base Class

Scripts inherit from ScriptBase. Most callable helpers are protected, so they are used from inside your script class.

public virtual string ScriptName

Defaults to the class name. Used in logs and script event sender info.

public virtual string ScriptDescription

Optional description text for tools that surface script metadata.

protected GameObject gameObject

The object that owns this script instance.

protected Transform transform

The transform of the owning object.

protected Dictionary<string, GameObject> slots

Named object slots assigned by the runtime when available.

protected bool IsRuntimeMode

True when running in the runtime world rather than editor bootstrap mode.

protected virtual bool SyncTransformStateByDefault

Defaults to true. Override to disable automatic transform state sync at startup.

protected bool TransformStateSyncEnabled

Runtime switch for automatic transform state synchronization.

ScriptAPI / Types

Core Types

SceneObject

Serialized scene reference with ObjectId, Id, IsNull, Exists, gameObject, transform, GetComponent<T>, GetComponents<T>, child lookup, and parent lookup helpers.

Sitpoint : SceneObject

Scene object reference with SitpointId resolution for sitpoint components and settings.

AvatarClone : SceneObject

Server-spawned avatar clone reference with SourceUsername, DisplayName, CloneId, and helper methods for destroy, transform, emote, sitpoint, and stand commands.

SceneLight : SceneObject

Scene object reference with a light property that resolves a Light on the object or in children.

InventoryItem

Inventory reference with InventoryId, Kind, Id, IsNull, IsEmpty, Exists, and normalization helpers.

TextureItem : InventoryItem

A texture inventory item (a picture, such as a backpack icon). Kind is Texture. Inspector fields of this type take only textures.

Emote : InventoryItem

An emote. In the scene editor, a public Emote field (or List<Emote>) shows a dropdown of the scene author's own emotes, uploaded or bought in the Avatar Editor; pick one there. Emotes are not typed in by id. Kind is Emote; EmoteId mirrors InventoryId; check IsNull before using it.

UserInfo

User snapshot with Username, ObjectName, ObjectId, and PlayerObject.

SitpointInfo

Sit or stand snapshot with Username, SitpointId, ObjectName, ObjectId, Sitpoint, and PlayerObject.

InteractionInfo

Interactable callback data with Username, ObjectName, ObjectId, ScriptNetworkId, InteractionType, and Target.

ChatCommandInfo

Chat command callback data with Username, UserId, player object fields, room ids, FullText, Command, ParameterText, and split Args.

SitpointInputInfo

Sitpoint input data with MoveX, MoveY, LookX, LookY, Jump, Sprint, Username, SitpointId, and Sitpoint.

TriggerInfo

Trigger callback data with EventType, IsPlayer, username, object name/id, trigger object id, OtherObject, and TriggerObject.

CollisionInfo

Collision callback data with IsPlayer, username, collided object name/id, collision object id, OtherObject, and CollisionObject.

BackpackSelection

A player's pick in the world's backpack: Username, UserId, Index, Item, DisplayName, PlayerPosition, Forward, Yaw, SpawnPosition(distance, height). See Backpack.

TriggerEventType

Enum values: Enter, Exit.

CharacterPhysicsMode

Enum values: Standing, Falling, Sleep.

CharacterImpactPart

Enum values: All, Core, LeftArm, RightArm, LeftLeg, RightLeg, Head.

CharacterRagdollSettings

Fields: Strength (0.12), GravityScale (1), Damping (0.02), Friction (0.6), Bounciness (0.08). Used with SetCharacterRagdollSettings.

Script Event Data

ScriptEventData.Set(name, value)

Adds or replaces a named event value and returns the same data object.

Has(name)

Checks whether the data contains a key. Keys are case-insensitive.

Get(name, defaultValue)

Gets a raw value or default.

Get<T>(name, defaultValue)

Gets and converts a value to the requested type when possible.

TryGet<T>(name, out value)

Gets a typed value and reports whether the key existed.

GetString / GetInt / GetFloat / GetDouble / GetBool

Convenience typed accessors for common event payload values.

Copy()

Returns a shallow copy of the event data.

ScriptEventData.From(params object[] pairs)

Builds event data from alternating name/value pairs.

Script Event Info

ScriptEventInfo

Contains EventName, Group, FullName, SenderScriptName, SenderObjectId, SenderObject, and Data.

ScriptAPI / Lifecycle

Lifecycle And Mode Helpers

public virtual void Start()

Called when the script starts. Call base.Start() before custom setup.

public virtual void OnDestroy()

Called as the script is destroyed. Use for cleanup such as despawning objects or stopping state.

public virtual void OnEnable()

Called when the script is enabled.

public virtual void OnDisable()

Called when the script is disabled.

public virtual void OnEvent(string eventName, object data)

Generic event hook for runtime-dispatched events.

SetTransformStateSync / DisableTransformStateSync / EnableTransformStateSync

Control automatic transform state synchronization for this script.

protected void SetStateApplyPhase(int phase)

Advanced control for when state is applied. The base uses the update phase.

ScriptAPI / Users And Events

Users

OnUserJoin(UserInfo user)

Override to run logic when a user enters.

OnUserPart(UserInfo user)

Override to run logic when a user leaves.

OnUserSit(SitpointInfo sitpoint)

Override to run logic when a user sits.

OnUserStand(SitpointInfo sitpoint)

Override to run logic when a user stands.

GetUsers()

Returns a list of active user snapshots.

GetUsernames()

Returns the active usernames known by the runtime.

ForEachUser(Action<UserInfo> callback)

Runs the callback for each active user and logs callback errors.

Script Events

Script events are local runtime messages. Use eventName for global listeners, or eventName@group for a grouped event key. Posting name@group notifies listeners of name and listeners of name@group.

CreateScriptEventData(params object[] nameValuePairs)

Builds ScriptEventData from alternating name and value arguments.

NewScriptEventData(params object[] nameValuePairs)

Alias for CreateScriptEventData.

ListenForScriptEvent(string eventName, Action<ScriptEventInfo> callback)

Registers a callback with full sender and payload details.

ListenForScriptEvent(string eventName, Action<ScriptEventData> callback)

Registers a callback that receives only the payload data.

StopListeningForScriptEvent(string eventName = null)

Stops this script's event subscriptions. With no name, removes all subscriptions owned by this script.

PostScriptEvent(string eventName)

Posts an event with empty data.

PostScriptEvent(string eventName, ScriptEventData data)

Posts an event with structured data.

PostScriptEvent(string eventName, params object[] nameValuePairs)

Posts an event from alternating name and value arguments.

ScriptAPI / Dialogs

Dialogs

ShowDialog queues a modal dialog client command. Provide targetUsername for a single user, or leave it empty for everyone. The dialog opens in the middle of the player’s screen in the platform’s own UI style (desktop, mobile and VR), with the icon (Info, Warning, Error, Success) and the buttons you choose (OK, OKCancel, YesNo, YesNoCancel); the button pressed comes back to onResult. Closing it counts as Cancel (or No when there is no Cancel).

ShowDialog(title, message, targetUsername = null, icon = Info, buttons = OK)

Shows a simple dialog with optional target, icon, and button set.

ShowDialog(title, message, ModalDialogIcon icon)

Shows an icon dialog with an OK button.

ShowDialog(title, message, icon, buttons, targetUsername = null)

Shows a dialog with explicit icon and button configuration.

ShowDialog(title, message, icon, buttons, onResult, targetUsername = null)

Shows a dialog and invokes the callback with ModalDialogResult.

ShowDialog(title, message, icon, onResult, targetUsername = null)

Shows an OK dialog and invokes the callback.

Dialog Enums

ModalDialogIcon

None, Info, Warning, Error, Success.

ModalDialogButtons

OK, OKCancel, YesNo, YesNoCancel, Custom.

ModalDialogResult

None, OK, Cancel, Yes, No, Custom1, Custom2, Custom3.

ScriptAPI / Transforms

Coroutines And Self Transform Helpers

StartCoroutine(IEnumerator routine)

Starts a coroutine using the script runtime runner.

yield return new WaitForSeconds(seconds)

Waits inside a coroutine. For example, yield return new WaitForSeconds(0.5f); waits half a second.

StopCoroutine(Coroutine routine)

Stops a coroutine started through the runtime runner.

StopAllCoroutines()

Stops all coroutines on the runner.

Move(Vector3 offset)

Adds the offset to this script object's world position.

Rotate(Vector3 eulerAngles)

Rotates this script object in world space.

RotateAround(Vector3 axis, float angle)

Rotates this script object around a world-space axis.

SetPosition / SetRotation / SetScale

Sets this script object's world position, world rotation, or local scale.

GetPosition / GetRotation / GetScale

Reads this script object's world position, world euler rotation, or local scale.

ScriptAPI / Object Commands

Self Object Client Commands

These helpers queue commands for the object that owns the script. Most include optional targetUsername, component index, and includeChildren parameters.

SetMaterialFloat(int materialIndex, string propertyName, float value, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Sets a material float property.

SetMaterialColor(int materialIndex, string propertyName, Color value, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Sets a material color property.

SetMaterialKeyword(int materialIndex, string keyword, bool enabled, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Enables or disables a material keyword.

SetRendererVisible(bool visible, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Sets renderer visibility.

SetRendererVisibleForUser(string targetUsername, bool visible, int rendererIndex = 0, bool includeChildren = true)

Changes this object's renderer visibility only for the named user. The private state is not replayed after the user leaves and rejoins. An empty username is rejected rather than becoming a broadcast.

SetLightEnabled / SetLightIntensity / SetLightColor

Controls a light component by index.

SetAudioVolume / SetAudioPitch / PlayAudio / StopAudio

Controls an audio source by index.

SetAnimatorTrigger / SetAnimatorBool

Controls animator parameters by index.

EnableAnimatorSync / DisableAnimatorSync

Periodically sends current Animator state to clients.

EnableLegacyAnimationSync / DisableLegacyAnimationSync

Periodically sends current legacy Animation state to clients.

SyncAnimatorState / SyncLegacyAnimationState

Sends current animation state once.

SetLocalPosition / SetLocalRotation / SetLocalScale

Queues a client transform command for this object.

LerpLocalPosition(Vector3 targetPosition, float lerpTime, string targetUsername = null)

Moves this object smoothly from its current position to the target over lerpTime seconds.

LerpLocalRotation(Vector3 targetEulerAngles, float lerpTime, string targetUsername = null)

Spherically interpolates this object's rotation to the target euler angles.

LerpLocalScale(Vector3 targetScale, float lerpTime, string targetUsername = null)

Interpolates this object's local scale to the target.

LerpLocalTransform(Vector3 targetPosition, Vector3 targetEulerAngles, Vector3 targetScale, float lerpTime, string targetUsername = null)

Interpolates position, rotation, and scale together using one command.

SetColliderEnabled / SetRigidbodyKinematic

Controls collider or rigidbody state by index.

Target Object Client Commands

These overloads take SceneObject targetObject first and queue the command for that object id.

SetMaterialFloat(SceneObject targetObject, int materialIndex, string propertyName, float value, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Sets a target object's material float property.

SetMaterialColor(SceneObject targetObject, int materialIndex, string propertyName, Color value, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Sets a target object's material color property.

SetObjectGlow(SceneObject targetObject, Color color, float strength, float fadeSeconds = 0f, string targetUsername = null)

Makes the whole object glow, children included: every material of every mesh gets the glow color at strength (2 is a clear glow), faded smoothly over fadeSeconds. Only this object glows, even when its materials are shared with others. Players who join later see it glowing.

ClearObjectGlow(SceneObject targetObject, float fadeSeconds = 0f, string targetUsername = null)

Fades the object back to its own materials' glow (as authored).

SetMaterialKeyword(SceneObject targetObject, int materialIndex, string keyword, bool enabled, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Enables or disables a target object's material keyword.

SetRendererVisible(SceneObject targetObject, bool visible, string targetUsername = null, int rendererIndex = 0, bool includeChildren = true)

Sets target renderer visibility.

SetRendererVisibleForUser(string targetUsername, SceneObject targetObject, bool visible, int rendererIndex = 0, bool includeChildren = true)

Changes a target object's renderer visibility only for the named user. The setting is temporary and a later public SetRendererVisible command replaces it normally.

SetLightEnabled / SetLightIntensity / SetLightColor

Controls a target light by index.

SetAudioVolume / SetAudioPitch / PlayAudio / StopAudio

Controls a target audio source by index.

SetAudioPitchByMotion(audioObject, minPitch, maxPitch, fullSpeed, volumeAtRest, motionObject, enabled)

Pitches and fades an audio source by how fast it moves in the world, measured by every viewer each frame: minPitch when still, maxPitch at fullSpeed metres per second. Works for parts moved by a model’s animation (no Rigidbody needed); a looping sound starts by itself when it first moves. motionObject measures another object instead; enabled: false puts the sound back to normal.

SetAnimatorTrigger / SetAnimatorBool

Controls a target animator by index.

SyncAnimatorState / SyncLegacyAnimationState

Sends a target object's current animation state once.

SetLocalPosition / SetLocalRotation / SetLocalScale

Queues a client transform command for a target object.

LerpLocalPosition(SceneObject targetObject, Vector3 targetPosition, float lerpTime, string targetUsername = null)

Moves a target object smoothly from its current position to the destination.

LerpLocalRotation(SceneObject targetObject, Vector3 targetEulerAngles, float lerpTime, string targetUsername = null)

Spherically interpolates a target object's rotation.

LerpLocalScale(SceneObject targetObject, Vector3 targetScale, float lerpTime, string targetUsername = null)

Interpolates a target object's local scale.

LerpLocalTransform(SceneObject targetObject, Vector3 targetPosition, Vector3 targetEulerAngles, Vector3 targetScale, float lerpTime, string targetUsername = null)

Interpolates all three transform channels on a target object using one command.

SetColliderEnabled / SetRigidbodyKinematic

Controls a target collider or rigidbody by index.

Timed transform behavior.

Leave targetUsername empty (or use *, all, or everyone) to run the interpolation on every client and on the shared instance-server object. A specific username runs only on that user's client and does not move the server copy. A newer lerp replaces the affected transform channel; an immediate SetLocalPosition, SetLocalRotation, or SetLocalScale cancels the matching lerp. For continuous motion, send future waypoints at a modest interval and make lerpTime equal to or slightly longer than that interval.

ScriptAPI / Material Emission

Material Emission At Runtime

SV Standard Lit materials expose _EmissionIntensity for glow strength and _EmissionColor for glow color. Set intensity above 0 to make the material emissive, and set intensity back to 0 with a black emission color to turn it off.

SetMaterialFloat(target, materialIndex, "_EmissionIntensity", level)

Sets the emission level. 0 is off; values like 1 to 3 are useful for visible glow.

SetMaterialColor(target, materialIndex, "_EmissionColor", color)

Sets the emitted color. Use a bright color while lit and Color.black when resetting.

_SVEmissionUseMap

Leave this off for normal SV Standard Lit glow through the base texture. Turn it on only when the material has a dedicated emission mask map.

SetMaterialFloat(target, 0, "_EmissionIntensity", 1.5f);
SetMaterialColor(target, 0, "_EmissionColor", Color.white);

SetMaterialFloat(target, 0, "_EmissionIntensity", 0f);
SetMaterialColor(target, 0, "_EmissionColor", Color.black);

ScriptAPI / Spritesheets

Spritesheet Material Helpers

Spritesheet helpers are target-object commands. They expect materials with the spritesheet properties used by the runtime animator.

SetSpritesheetFrame(SceneObject targetObject, int frame, string targetUsername = null, int rendererIndex = 0, int materialIndex = 0, bool includeChildren = true)

Sets the target material frame.

SetSpritesheetPlayback(SceneObject targetObject, bool animate, float autoAdvanceSeconds, bool loop, string targetUsername = null, int rendererIndex = 0, int materialIndex = 0, bool includeChildren = true)

Sets animation, frame advance interval, and looping.

SetSpritesheetMaterial(SceneObject targetObject, int? frame = null, bool? animate = null, float? autoAdvanceSeconds = null, bool? loop = null, bool? affectMaps = null, string targetUsername = null, int rendererIndex = 0, int materialIndex = 0, bool includeChildren = true)

Applies any combination of frame, playback, loop, and map-affecting settings. Commands are persistent for late-joining clients.

Without a targetUsername the change goes to the instance server's shared state of that material: every player sees the same frame at the same moment, including players who join later, and the material's own settings (Start Frame, Animate, Seconds / Frame, Loop) are only the starting point. Commands sent before anybody has loaded the scene are kept and applied when the first player arrives. With a targetUsername the change is shown to that user only and is not kept after they leave.

ScriptAPI / Animated Meshes

Animated Meshes

A model with animation takes has a legacy Animation component (and an Animator for the trigger / bool helpers). Its default take, whether it plays when the world opens, its speed and repeat mode are set in the scene editor's Inspector. Script calls change the instance server's shared state of the model, so every player sees the same take at the same time, also players who join later.

Animation anim = target.GetComponentInChildren<Animation>(true)

The model's animation. foreach (AnimationState s in anim) lists the takes with s.name and s.length (known once a player has loaded the scene).

anim.Play() / anim.Play("take") / anim.CrossFade("take")

Plays a take (empty = the default take). Playing the take that is already set continues from its current time; another take starts at 0.

anim.Stop() / anim.Stop("take") / anim.Rewind()

Stops (back to the rest pose), or jumps back to 0.

anim["take"].speed / .time / .normalizedTime / .wrapMode

Speed (0 freezes, negative plays backwards), jump to a time, and repeat mode: WrapMode.Loop, PingPong, Once (stops at the end), ClampForever (holds the last frame). anim.wrapMode sets it for the current take.

SetAnimatorTrigger(target, "name") / SetAnimatorBool(target, "name", bool)

Plays the take whose name contains name (a bool of false stops it). Animator.Play("take"), Animator.speed and Animator.enabled (pause / resume) also work.

SyncAnimatorState / SyncLegacyAnimationState / Enable…Sync

Still accepted; the state is always shared, so these only re-send it.

ScriptAPI / Spawning

Inventory Spawning And Player Controls

SpawnInventoryItem(InventoryItem item, Vector3 position, Vector3 eulerAngles, Vector3 scale)

Spawns an inventory item for everyone and returns it as a SceneObject; players who join later see it too. The item can be a mesh, a prefab or a system object (light, sitpoint, water, particles, media screen…), whichever was dropped on the script's InventoryItem field. A mesh spawns solid (a collider shaped like it). A prefab (Hierarchy → Save to Inventory) spawns with everything saved in it: rigidbodies fall and can be grabbed and thrown (simulated on the server), and scripts on it run on the server, one copy per spawned prefab. Each player downloads an item's model, textures and scripts once per visit, however often it is spawned.

DespawnSpawnedObject(SceneObject spawnedObject)

Removes a spawned object for everyone, with all its parts, their physics and the scripts that ran on them.

TeleportPlayer(string username, Vector3 position, Vector3 eulerAngles)

Queues a teleport command for one username.

PlayPlayerEmote(string username, Emote emote)

Plays the emote chosen in an Emote field on one user (everyone in the instance sees it). Nothing happens, with a warning in the log, if no emote was chosen.

PlayEmoteForAll(Emote emote)

Plays the emote on every user in the instance.

StopPlayerEmote(string username) / StopAllPlayerEmotes()

Stops the emote one user, or everyone, is playing.

SetPlayerScale(string username, float scale)

Sets uniform scale for one user.

SetPlayerScale(string username, Vector3 scale)

Sets non-uniform scale for one user.

SetAllPlayerScales(float scale) / SetAllPlayerScales(Vector3 scale)

Sets player scale for everyone.

SetMediaScreenUrl(string url)

Sets all media screens to a URL.

SetMediaScreenUrl(string mediaScreenId, string url)

Sets one media screen id, or * for all media screens.

SetMediaScreenUrlForUser(string targetUsername, string url)

Sets all media screens to a URL only for the named user. Stored database rows are ignored for that user until a live public media update arrives. The override is not restored after rejoining.

SetMediaScreenUrlForUser(string targetUsername, string mediaScreenId, string url)

Sets one media screen, or * for all screens, only for the named user. A public SetMediaScreenUrl or /media update releases the matching private override.

GetCurrentSceneIdentifier()

Returns the current scene instance EventID for the server script. This is useful for logs and instance-specific script behavior.

ScriptAPI / Backpack

Backpack

A world can give every player a backpack: a Backpack button on the control bar (desktop, mobile and VR) that opens a panel of item icons with their names, five across, scrolling when there are more. Worlds that do not set one up have no button and no panel. The panel takes the platform's theme like every other panel. See the Backpack example.

SetupBackpack(List<InventoryItem> items, List<TextureItem> icons, List<string> names, Action<BackpackSelection> onItemSelected)

Sets up the world's backpack for every player (and players who join later). Entry i of each list belongs together: items[i] is the item, icons[i] a texture for its picture and names[i] the name under it. An empty icon uses the item's own thumbnail; an empty name, the item's own name. onItemSelected runs on the server when a player picks an entry: your script decides what happens, usually SpawnInventoryItem in front of that player. One backpack per world: the latest call replaces it. Up to 200 entries.

RemoveBackpack()

Takes the backpack away: the button leaves every player's control bar and an open panel closes.

BackpackSelection

What a player picked: Username, UserId, Index (the entry), Item, DisplayName, PlayerPosition (their feet), Forward (the flat direction their avatar faces), Yaw (that direction in degrees, for a spawn rotation of new Vector3(0, Yaw, 0)) and PlayerObject.

BackpackSelection.SpawnPosition(float distance = 1.5f, float height = 1f)

A point distance metres in front of the player and height metres above their feet.

Inspector: InventoryItem, TextureItem and List<…> fields

Drag items from the Inventory panel onto the field. InventoryItem fields take things that can be spawned (prefabs, meshes and system objects); TextureItem fields take textures; other kinds are refused. In a list, drop on an entry to replace it or on the box at the end to add one. Lists are numbered from #0 so entries of different lists line up. List<string> fields get one text box per entry.

ScriptAPI / Avatar Clones

Avatar Clone Spawning

Avatar clones are spawned and animated on the instance server, then serialized to clients through player-style packets. Keep the returned AvatarClone reference if you want to move it, force emotes, slot it into a sitpoint, or destroy it later.

SpawnAvatarClone(string username, Vector3 position)

Spawns a clone of the named user's avatar at a world position and returns an AvatarClone reference.

SpawnAvatarClone(string username, Vector3 position, Vector3 eulerAngles)

Spawns a clone with a world position and rotation.

SpawnAvatarClone(string username, Vector3 position, Vector3 eulerAngles, Vector3 scale, string outfitName = null)

Spawns a clone with an explicit rotation and scale. The clone wears the user's outfit named outfitName (the name they gave it in the Avatar Editor; capitals do not matter), or the outfit they are wearing when outfitName is blank or they have no outfit by that name. The clone's OutfitName keeps the name asked for.

DestroyAvatarClone(AvatarClone clone)

Destroys a spawned clone. Clients remove it when the server stops sending clone packets.

SetAvatarClonePosition(AvatarClone clone, Vector3 position)

Moves a clone to a world position.

SetAvatarCloneRotation(AvatarClone clone, Vector3 eulerAngles)

Sets clone world rotation in Euler angles.

SetAvatarCloneScale(AvatarClone clone, Vector3 scale)

Sets clone scale.

SetAvatarCloneTransform(AvatarClone clone, Vector3 position, Vector3 eulerAngles, Vector3 scale)

Sets clone position, rotation, and scale in one command.

PlayAvatarCloneEmote(AvatarClone clone, Emote emote)

Makes the clone play the emote chosen in an Emote field. The resulting bones are serialized to clients like player bones.

StopAvatarCloneEmote(AvatarClone clone)

Stops the clone's forced emote.

SeatAvatarClone(AvatarClone clone, Sitpoint sitpoint)

Slots the clone into a slotted Sitpoint.

StandAvatarClone(AvatarClone clone)

Removes the clone from its current sitpoint.

AvatarClone Reference Methods

clone.Destroy()

Same as DestroyAvatarClone(clone).

clone.SetPosition(position) / SetRotation(eulerAngles) / SetScale(scale) / SetTransform(position, eulerAngles, scale)

Convenience methods for controlling the cached clone reference.

clone.PlayEmote(emote) / clone.StopEmote()

Convenience methods for forcing or stopping server-side clone emotes.

clone.Ragdoll(CharacterRagdollSettings settings = null, float autoStandAfterSeconds = 0f) / clone.StandUp(float transitionSeconds = 0.8f)

Turns the clone into a ragdoll (it falls onto whatever is below, like a player) and gets it back up where the body lies. Also SetAvatarCloneRagdoll(clone, true / false). Sitting, moving or destroying the clone ends the ragdoll.

clone.ApplyImpact(Vector3 direction, float power = 8f, float durationSeconds = 0.15f, float autoStandAfterSeconds = 0f, CharacterImpactPart part = CharacterImpactPart.All)

Hits the clone (it becomes a ragdoll if it is not one yet): power metres per second in direction. Also ApplyAvatarCloneImpact(clone, …).

clone.Sit(sitpoint) / clone.Stand()

Convenience methods for sitpoint slotting.

public Emote selectedEmote;
public Sitpoint cloneSeat;

AvatarClone clone;

void SpawnOne(string username)
{
    clone = SpawnAvatarClone(username, transform.position + Vector3.forward * 2f);
}

void ToggleEmote()
{
    if (clone != null && !clone.IsNull)
        clone.PlayEmote(selectedEmote);
}

void SitClone()
{
    if (clone != null && !clone.IsNull)
        clone.Sit(cloneSeat);
}

void RemoveClone()
{
    if (clone != null && !clone.IsNull)
        clone.Destroy();
}

ScriptAPI / Character Physics

Character Physics

Ragdoll physics for players. Falling, Sleep and impacts with fall = true turn the player's body into a ragdoll: it falls with gravity onto floors, terrain and furniture, gets pushed around by moving physics objects, and stays down until it is stood up again (by StopCharacterPhysicsMode or an auto-stand delay). The player cannot walk while ragdolled, and gets up where the body lies. A body lying on a surface uses that surface's Collider Friction and Bounciness (with its Combine modes) together with the ragdoll's own settings, and comes to rest once it stops moving; an impact, a player walking into it or a moving physics object wakes it again. Avatar clones can be ragdolled too (clone.Ragdoll, below). The player's own viewer simulates the body and everyone in the instance sees the same fall. Use "*" as the username for everyone.

SetCharacterPhysicsMode(string username, CharacterPhysicsMode mode, float transitionSeconds = 0.8f, float autoStandAfterSeconds = 0f)

Falling: ragdoll with the current ragdoll settings (use it for fall trigger zones). Sleep: a completely limp ragdoll. Standing: get up, blending back to normal animation over transitionSeconds. Set autoStandAfterSeconds above 0 to get up automatically.

StopCharacterPhysicsMode(string username, float transitionSeconds = 0.8f)

Gets the player up from a ragdoll: they stand where the body lies, and the pose blends back to normal over transitionSeconds (0 = at once).

SetCharacterRagdollSettings(string username, CharacterRagdollSettings settings)

How that player's ragdoll behaves from now on (also while already ragdolled): Strength (muscles: 0 = limp, 1 = stiff as a statue; about 0.1–0.2 looks like a person falling), GravityScale (1 = normal), Damping (air drag, 0–0.95), Friction (0 = slides, 1 = stops where it lands), Bounciness (0–1).

ApplyCharacterImpact(string username, Vector3 direction, float power = 8f, float durationSeconds = 0.15f, bool fall = true, float autoStandAfterSeconds = 0f, CharacterImpactPart part = CharacterImpactPart.All)

Hits the player: power is the speed (metres per second) added in direction, spread over durationSeconds, to the body part (or the whole body). With fall = true the player becomes a ragdoll (or is pushed further if already one); with fall = false a standing player is only pushed. direction = Vector3.zero, power = 0, fall = true simply collapses the player.

// Start falling for the player who entered a trigger.
SetCharacterPhysicsMode(info.Username, CharacterPhysicsMode.Falling, 0.15f);

// Stop when the player reaches the landing trigger.
StopCharacterPhysicsMode(info.Username, 0.8f);

// Drop in place and recover after 3 seconds.
ApplyCharacterImpact(info.Username, Vector3.zero, 0f, 0f, true, 3f);

// A floppy, low-gravity ragdoll, then knock the player backwards off their feet.
CharacterRagdollSettings floppy = new CharacterRagdollSettings();
floppy.Strength = 0.05f;
floppy.GravityScale = 0.6f;
SetCharacterRagdollSettings(info.Username, floppy);
ApplyCharacterImpact(info.Username, new Vector3(0f, 0.5f, -1f), 6f, 0.15f, true, 4f);

ScriptAPI / Chat

Chat Commands And Room Messages

RegisterChatCommand(Action<ChatCommandInfo> callback)

Listens for every non-system slash command that was not handled by the game client command list.

RegisterChatCommand(string command, Action<ChatCommandInfo> callback)

Listens for one custom slash command such as /roll. The leading slash is optional. Built-in commands (/yt, /media, /help, /alert, /kick, /ban and the other admin and recording commands) are handled by the viewer and cannot be registered: the script log says so and the command is skipped.

StopListeningForChatCommand(string command = null)

Removes this script's chat command listener for one command, or all chat command listeners when omitted.

SendScriptChat(string message)

Inserts a room chat history entry from the fake username [Script].

ScriptAPI / Interaction

Interactables, Triggers, Collisions, And Sitpoint Input

MakeInteractable(Action<InteractionInfo> onInteract, bool highlight = true, string targetUsername = null, bool includeChildren = true, float raycastDistance = 10f, string hintText = null)

Makes the script object interactable and calls the callback when activated.

MakeInteractable(SceneObject targetObject, Action<InteractionInfo> onInteract, bool highlight = true, string targetUsername = null, bool includeChildren = true, float raycastDistance = 10f, string hintText = null)

Makes a target object interactable.

RegisterTrigger(Action<TriggerInfo> onEnter, Action<TriggerInfo> onExit = null, bool includeChildren = true)

Registers trigger callbacks on the script object.

RegisterTrigger(SceneObject targetObject, Action<TriggerInfo> onEnter, Action<TriggerInfo> onExit = null, bool includeChildren = true)

Registers trigger callbacks on a target object.

RegisterCollision(Action<CollisionInfo> onCollision, bool includeChildren = true)

Registers a server-side collision callback on the script object. The callback receives the collided object's ObjectName and ObjectId.

RegisterCollision(SceneObject targetObject, Action<CollisionInfo> onCollision, bool includeChildren = true)

Registers a server-side collision callback on a target object or its child colliders.

RegisterSitpointInput(Action<SitpointInputInfo> onInput)

Registers a callback for input from the sitpoint associated with this script's network id.

ScriptAPI / Advanced

Advanced Helpers

EmitClientCommand(string command, string payloadJson, string targetUsername = null)

Queues a raw client command for this script object's network id.

EmitClientCommand(SceneObject targetObject, string command, string payloadJson, string targetUsername = null)

Queues a raw client command for a target object id.

Log(string msg)

Writes a normal log message prefixed with the script name.

LogWarning(string msg)

Writes a warning prefixed with the script name.

LogError(string msg)

Writes an error prefixed with the script name.