Sansar Docs
  • 🚀Welcome to Sansar
  • 📚GLOSSARY
  • 🎏Patch Notes
  • 😇Work in Progress
  • ⚠️Creative Commons License
  • Support
    • General Troubleshooting
      • General FAQ
      • The Sansar Cache
      • The Sansar Log
    • Contact Support
  • Sansar Basics
    • Installation And Compatibility
      • Installing Sansar
      • System Requirements
      • Sansar Compatibility FAQ
      • Sansar on Mac
      • Body Tracking Vive
      • Configuring Firewalls
    • Account Management
      • Account Set Up
      • Avatar Name and ID
      • Adding Payment Method
      • Discord FAQ
      • Steam Integration
      • Subscription FAQ
    • Controls
      • Avatar Hand Gestures in VR
      • FreeCam and CineCam
      • Game Controller Buttons
      • HTC VIVE controls
      • Keyboard Shortcuts for Editing a Scene
      • Keyboard Shortcuts for Styling Your Avatar
      • Keyboard Shortcuts for Visiting an Experience
      • Mouselook Mode
      • Oculus Rift Controls
      • Vive Index Controls
    • Settings
      • General Settings
    • VR Settings
      • VR Settings Menu
      • Calibrating Height in VR
  • Exploring in Sansar
    • Navigate and Explore
      • The Codex
      • Instances
      • Interactive objects
      • The Main Menu
      • The Nexus
      • Portals
      • Quests
      • Quick Start: Exploring in Sansar
    • Socialize And Connect
      • Chat Panel
      • Experience Points, Levels, and Titles.
      • Finding People in Sansar
      • Identifying Interacting With Avatars
      • The People panel
      • User profiles
    • Attending events
      • Deploying Unpublished Event to Event World
      • Adding Events to Your Calendar
      • Attending Events in Sansar
      • Avatar Broadcasting FAQ
      • Creating Your Own Events
      • Redemption Codes
      • Tipping
    • Share Content
      • Streaming Sansar
      • Taking a photo
  • Avatar Creation
    • Avatar Basics
      • Avatar 2.0 FAQ
      • Customizing Your Avatar
      • Avatar Emotes
      • The Avatar Editor
    • Dressing The Avatar
      • Fitting Designer Clothing to your Avatar
      • Setting Custom Emotes
      • Wearing Accessories
      • Wearing Rigged Clothing
    • Managing Avatar Items
      • Importing Avatar-Related Items
      • Editing an inventory item's name
      • Editing an inventory item's image
      • Deleting avatar looks from your inventory
      • Importing a custom emote animation
      • Managing your avatar looks inventory items
    • Avatar Resources
      • Avatar Reference Files
      • Blender - Avatar files
      • Blender - Using Decimate Tool
      • Exporting Custom Avatars From Blender
      • Sansar Skeleton Skinning Details
      • Using Animation Skeleton
  • Creating In Sansar
    • Importing Things to Sansar
      • Supported file types
      • AABB Bounding Box and Item Restrictions
      • Importing Audio
      • Importing a Custom Avatar
      • Importing World Items
      • Importing Collision Volumes
      • Importing Accessories
      • Importing Clothing
      • Importing Emotes
      • Importing Hair
      • Importing Custom Scripts
      • Importing a Skybox
      • Troubleshooting Import Errors
    • Shaders and Materials
      • Shaders Information
      • Materials Information
      • VAT Shader Guides
        • VAT Shader Basics
        • VAT Technical Info
      • Displacement Guides
        • Simple Displacement
        • Advanced Displacement
    • Marvelous Designer Info
      • Marvelous Designer Integration
      • Marvelous Designer Creator Resources
      • Marvelous Import and Export
      • MD Limitations
    • Shader Scripting
    • Materials editing and shaders
    • Creator Tools
      • Creating a World
      • Creating Quests
      • Diagnostics Toolbar
      • Importing Items to Sansar
      • My Worlds Panel
    • Managing Worlds
      • Quick start: Creating experiences in Sansar
      • Deleting an experience or scene
      • Deploying a new scene to an existing experience
      • Editing a scene
      • Experience memos
      • Linking A Scene To A World
      • Managing your scenes and worlds
      • Moderation Tools for World Owners
      • Publishing Options for Your Experiences
      • Renaming a scene
      • Saving and Building A Scene
      • Sharing Your Experiences
      • Visiting your own experience
    • Part Of The World Editor
      • Object Stats Toolbar
      • Object Components
      • Parenting objects
      • Scene Item Inventory
      • Scene Objects Panel
      • Collision Volumes
      • Scene Settings
      • System objects
      • Object Motion Types
    • Working With Scripts
      • Working With Scripts
      • Working With Trigger Volume
      • Referencing Scene Components
      • Intro to Scripting in Sansar
      • Using the Script Console
      • Setting Script Parameters
      • Adding Scripts to an Object
      • Configuring Teleport Scripts
      • Simple Script User Guide
    • Working With Audio and Video
      • Working With Audio
      • Creating Media surface
      • Streaming Web Audio
      • Audio Emitter
      • Sansar Audio FAQ
      • Using Media Streams
      • Ambisonic Sounds
      • High Quality Spacial Audio
      • Audio Resource - Room Tones
      • Previewing Audio and Video in a Scene
      • Using Audio Materials
    • Working With Lights
      • Working With Lights
      • Light Types
      • Global Illumination
  • Sansar Store
    • Using the Sansar Store
      • The Sansar Store
      • Buying Items From The Store
      • Redelivering Lost Purchases
    • Buying and Selling Sansar Dollars
      • Gifting Sansar Dollars
      • Buying Sansar Dollars
      • Converting Sansar Dollars
      • Processing US Dollar Credit
    • Selling Your Content
      • Hidden Store Listings
      • Selling Items in Sansar Store
      • Selling Items in an Experience
      • Allowing Resale Of Items
      • Buyers Permissions
  • Guidelines and Moderation
    • Guidelines and Policies
      • Terms of service
      • Sansar's Discord Server Rules
      • Community Standards
      • Content Guidelines
      • World Publishing Guidelines
      • Store Listing Guidelines
      • Store Banner Guidelines
      • Event Guidelines
      • Privacy Policy
      • Sansar Freeware License Agreement
      • Intellectual Property Infringement Notification
      • Cookie Policy
    • Moderation and Reporting
      • Abuse and Griefing
      • Blocking Avatars
      • Muting Avatars
      • Reporting abuse
      • Reporting issues and bugs
      • Security issues
  • Script API Docs
    • General Information
      • External Script Repository's
      • Sansar Script API
      • Script API Updates
      • Restricted API's
    • Example Scripts
      • Example Scripts in Sansar
      • Cannonball
      • Follow The Path
      • Random Movement
      • Reflective Detector
      • Simple Script
      • Sound Randomizer
      • Stats Example
      • Teleport Hotkeys
      • Visitor Tracker
      • Mover Examples
    • Sansar Namespace
      • Namespace
      • Color
      • Mathf
      • Quarterion
      • Vector
      • Vector Extensions
    • Sansar.Script Namespace
      • AddEntryAttribute
      • CancelData
      • ComponentID
      • CoroutineException
      • Default Attributes
      • Editor Visible Attribute
      • Entries Attribute
      • Event Data
      • ICoroutine
      • IEvent Subscription
      • Instance Interface
      • Locked Attribute
      • Log
      • MaxEntriesAttribute
      • Memory
      • MinEntriesAttribute
      • NonReflectiveAttribute
      • ObjectID
      • OperationCompleteEvent
      • RangeAttribute
      • Reflective
      • Script.Base
      • Script Event Data
      • Script Handle
      • ScriptID
      • SessionID
      • Simple Script Event Data
      • ThrottleException
      • Timer
      • Tooltip Attribute
    • MetaData Namespace
      • Assembly MetaData
      • Script MetaData
    • Sansar Script Testing Namespace
      • Assertion Failure Exception
      • Assertions
    • Sansar Utility Namespace
      • GenericEnumerable <T>
      • GenericEnumerable<T>.GetItem
      • JSON Serialization Data
      • JSON Serialization Data 1
      • JSON Serializer
      • JSON Serializer Options
    • Sansar Simulation Namespace
      • Agent Info
      • Animation
      • Audio Component
      • Camera Control Mode
      • Character Tracker
      • Chat
      • Client
      • Cluster
      • Command Action and Data
      • Component Type
      • Control Point Type
      • Held Object
      • HTTP
      • Interaction
      • Light
      • Media Action
      • Mesh Component
      • Modal Dialogue
      • Move Mode and Mover
      • Objective
      • PlayHandle
      • PlaySettings
      • PlayStatus
      • Quest
      • RayCastHit
      • Rigid Body
      • Scene
      • Scene Public
      • Simple Script
      • Sit Event Type
      • Sit Object Data
      • Sound Resource
      • Stream Channel
      • Tutorial Hint
      • UI
      • User Data
Powered by GitBook
On this page
  • Working with trigger volumes
  • Using trigger volumes
  • Adding a trigger volume to a scene
  • Testing the trigger volume
  • Trigger volume main properties
  • Changing the Volume Type
  • TriggerAnnounce Example Script
  1. Creating In Sansar
  2. Working With Scripts

Working With Trigger Volume

PreviousWorking With ScriptsNextReferencing Scene Components

Last updated 1 year ago

Working with trigger volumes

A is an invisible, non-collidable area that generates a whenever an object or avatar enters or exits the area. This can be useful for opening automatic doors, counting visitors, and many other applications.

Using trigger volumes

Here are some steps to set up a trigger volume. For the purpose of this guide, we will be using the example script , which announces when something enters or exits the trigger volume.

Adding a trigger volume to a scene

  • Create a new experience as described in . For simplicity, choose the Base Template scene as the experience's starting template.

  • Remember that trigger volumes are invisible. You may want to consider using visible objects to identify the trigger location or not, depending on your desired outcome.

    In this example, place two or more visible objects in such a way that you can easily navigate between them. We have used the free from the . This step is to make sure we can find the trigger volume while visiting the scene.

  • From the System Objects tab of your Inventory, drag a new Trigger Volume into the scene.

    In this example, position it between the visible objects you have placed, such that a visitor must pass through the trigger volume in order to walk between the visible objects.


  • Save, then Build your scene.

  • When the scene has finished building, click the Visit Now button that appears to visit your scene.

Testing the trigger volume

When visiting the scene, walk into the trigger volume to trigger the attached script. Remember that trigger volumes are invisible to visitors, so you should walk towards the visible object markers, if there is one.


Trigger volume main properties

To access the trigger volume's properties, find the trigger volume's name in the Scene Objects panel, right-click it, and choose Properties to open its Properties panel.


The trigger volume properties include:

Position - The location of the trigger volume's center.

Rotation - The trigger volume's orientation in the scene.

Scale - Increases or decreases the size of the entire trigger volume; defaults to 1.0.

Movable From Script - Set to On to allow scripts to move, rotate, and scale the trigger volume.

Changing the Volume Type

You can change a trigger volumes shape by accessing the volume component within the trigger volume's container. To access this:

  1. Find the trigger volume's name in the Scene Objects panel and click on the blue arrow beside the name to drop down the trigger volume's list of components.

  2. Find the Volume component and right-click it to open a sub-menu of actions.

  3. Then, choose Properties from the sub-menu to open the volume Properties panel.

The properties in the volume-specific properties panel include:

VolumeType - The volume properties panel allows you to set the shape of the trigger volume to either a Box or Sphere by using the drop down. Box is the default volume type. Keep in mind that this can only be set in the Volume properties panel.

Note: Mesh is currently a selectable VolumeType on the drop down list. However, it is currently not supported with trigger volumes.

Depending on whether you've chosen to use Box or Sphere as the VolumeType, you will see the following show up on the volume properties panel and the trigger volume's main properties panel:

Extents - For the Box VolumeType only; defines the proportions of the trigger volume in the X, Y, and Z coordinates.

Radius - For the Sphere VolumeType; defines the radius of a spherical trigger volume.

Note: While HasCollision appears on the volume properties panel, it is currently not supported with trigger volumes.


TriggerAnnounce Example Script

using Sansar.Simulation;

/// <summary>
/// TriggerAnnounce announces on chat when someone (or some thing) enters the volume the script is attached to.
/// </summary>
public class TriggerAnnounce : SceneObjectScript
{
    public override void Init()
    {
        RigidBodyComponent rigidBody;
        // Collision events are related to the RigidBody component so we must find it.
        // See if this object has a RigidBodyComponent and grab the first one.
        if (ObjectPrivate.TryGetFirstComponent(out rigidBody)
            && rigidBody.IsTriggerVolume())
        {
            // Subscribe to TriggerVolume collisions on our rigid body: our callback (OnCollide) will get called
            // whenever a character or character vr hand or dynamic object collides with our trigger volume
            rigidBody.Subscribe(CollisionEventType.Trigger, OnCollide);
        }
        else
        {
            // This will write to the script console
            Log.Write("Couldn't find rigid body, or rigid body is not a trigger volume!");
        }
    }

    // "Collision" events are really RigidBody events, and they get RigidBodyData.
    private void OnCollide(CollisionData data)
    {
        // Ignore hands:
        if (data.HitControlPoint != ControlPointType.Invalid) return;

        if (data.Phase == CollisionEventPhase.TriggerEnter)
        {
            ScenePrivate.Chat.MessageAllUsers($"Object {data.HitComponentId.ObjectId} has entered my volume!");
        }
        else
        {
            // HitObject might be null if the object or avatar is no longer in the scene, here we are just reporting the object id.
            ScenePrivate.Chat.MessageAllUsers($"Object {data.HitComponentId.ObjectId} has left my volume!");
        }
    }
}

Choose a script that makes use of the .

For the purposes of this example, upload the script.

Drag the script onto the trigger volume, or on the trigger volume container.

In the exercise above, the example script, , is added to the trigger volume in between two (visible) objects. Walk into the area indicated by the visible objects you placed earlier to trigger the script. When you enter or exit the trigger volume, example script causes the trigger volume to log your entry or exit in chat.

Note**:** In order to view chat messages from any script, you must have the open.

Collides With - Determines what kinds of objects can activate the trigger volume. For the best performance, Avatars and Dynamic Bodies is selected by default, but you can allow additional object types by selecting Everything from the dropdown. For additional information about the types of movable objects, including dynamic objects, see .

Extents / Radius - May show one or the other based on the VolumeType selected. Changing the VolumeType defines the shape of the trigger volume. See below for information on Extents and Radius and how to change the VolumeType between a Box or a Sphere.

Trigger event
add a script component
Chat app
Object motion types
changing the volume type
triggerannounce.cs
triggerannounce.cs
trigger volume
Trigger event
Quick start: Creating experiences in Sansar
Sansar Example Crate 1.0
Sansar Store
triggerannounce.cs
The trigger volume is between the two visible objects in such a way that visitors must pass through the trigger volume when walking between the two crates.
When entering the invisible trigger volume, triggerannounce.cs announces your entry in the Chat app.
The Properties panel for a trigger volume.
Selecting the VolumeType from the properties of the trigger volume's Volume component.