Event Listeners
This document provides several guides that can be used to setup event listeners in a VIVERSE project. The event listeners use triggers. Triggers can be configured to perform actions once activated.
Last updated
This document provides several guides that can be used to setup event listeners in a VIVERSE project. The event listeners use triggers. Triggers can be configured to perform actions once activated.
Last updated
© 2024 HTC CORPORATION
Create A Trigger Based On When An Object Enters An Area
This guide provides instructions for setting up the EntitySubscribeTriggerEnter trigger. In the sample app, the trigger areas are outlined in blue. Once the avatar enters into the blue area, an action occurs.
The avatar is outside the blue trigger area and the gold coin is not visible.
The avatar has entered the blue trigger area and the gold coin is visible.
In this example, a trigger area is created and when the avatar or other objects enter the area, an action is initiated. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example creates an empty area that the avatar and other objects can pass through, a simple entity with a box shape is used instead of a 3D object. The entity does not have a RigidBody component added. Right-click in the Hierarchy and select New Entity > Entity.
A. Click the "Add Component" button. Select Physics > Collision to add a Collision component.
B. Resize the collider to the desired size. In this example, the Half Extents field has been set to (2.5, .5, 2.5) for X, Y, Z.
C. The entity itself is currently set to Position (0, 0, 0) for X, Y, Z. In this example, the values for Position Offset are set to (0, -2, 0) for X, Y, Z to lower the collider to the ground.
D. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select the EntitySubscribeTriggerEnter option in the dropdown menu.
E. Click the tags to filter dropdown and select local-player tag
F. Click "+" beside the selected module dropdown.
G. Click the type dropdown and select a desired action. In this example, the EntityEnableById action is selected. For the EntityEnableById action to work, an object needs to be added that will be enabled. In this example, the golden_coin object is added.
Create A Trigger Based On When An Object Leaves An Area
This guide provides instructions for setting up the EntitySubscribeTriggerLeave trigger. In the sample app, the trigger areas are outlined in blue. Once the avatar leaves the blue area, an action occurs.
The avatar is inside the the blue trigger area and the gold coin is visible.
The avatar leaves the blue trigger area and the gold coin is no longer visible.
In this example, a trigger area is created and when the avatar or other objects leave the area, an action is initiated. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example creates an empty area that the avatar and other objects can pass through, a simple entity with a box shape is used instead of a 3D object. The entity does not have a RigidBody component added. Right-click in the Hierarchy and select New Entity > Entity.
A. Click the "Add Component" button. Select Physics > Collision to add a Collision component.
B. Resize the collider to the desired size. In this example, the Half Extents field has been set to (2.5, .5, 2.5) for X, Y, Z.
C. The entity itself is currently set to Position (0, 0, 0) for X, Y, Z. In this example, the values for Position Offset are set to (0, -2, 0) for X, Y, Z to lower the collider to the ground.
D. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select the EntitySubscribeTriggerLeave option in the dropdown menu.
E. Click "+" beside the selected module dropdown.
F. Click the type dropdown and select a desired action. In this example, the EntityDisableById action is selected. For the EntityDisableById action to work, an object needs to be added that will be disabled. In this example, the golden_coin object is added.
Create A Trigger Based On When An Object Collides With Another Object
This guide provides instructions for setting up the EntitySubscribeCollisionStart trigger. In the sample app, the golden_coin is a trigger. Once the avatar collides with the golden_coin, an action occurs.
The avatar approaches the gold coin.
Once the avatar collides with the gold coin, the gold coin is removed.
In this example, a trigger is created and when the avatar or other objects collide with the trigger, an action is initiated. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example uses a 3D object that the avatar and other objects can collide with, a RigidBody component needs to be added. In this example, the object golden_coin is used, but a simple cube will suffice.
A. Click the "Add Component" button. Select Physics > Collision to add a Collision component. Click the "Add Component" button again and select Physics > Rigid Body to add the RigidBody component.
B. In this example, the golden_coin has a Mesh collider that encompasses the entire object by default. Resize the collider here if the collider's size needs to be changed.
C. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select the EntitySubscribeCollisionStart option in the dropdown menu.
E. Click "+" beside the selected module dropdown.
F. Click the type dropdown and select a desired action. In this example, the EntityDisable action is selected.
Create A Trigger Based On When An Object Stops Colliding With Another Object
This guide provides instructions for setting up the EntitySubscribeCollisionEnd trigger. In the sample app, a flattened 3D cube is a trigger. Once the avatar stops colliding with the cube, an action occurs.
The avatar is colliding with the red platform.
Once the avatar stops colliding with the red platform, the red platform begins to fade out.
In this example, a trigger is created and when the avatar or other objects collide with the trigger, an action is initiated. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example uses a 3D object that the avatar and other objects can collide with, a RigidBody component needs to be added. In this example, a 3D cube is used. Right-click in the Hierarchy and select New Entity > 3D > Box.
A. In this example, the cube has been flattened by setting the values for Scale to (2, .1, 2) for X, Y, Z.
B. Click the "Add Component" button. Select Physics > Collision to add a Collision component. Click the "Add Component" button again and select Physics > Rigid Body to add the RigidBody component.
C. Resize the collider to the desired size. In this example, the Half Extents field has been set to (.5, .05, .5) for X, Y, Z.
D. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select the EntitySubscribeCollisionEnd option in the dropdown menu.
E. Click "+" beside the selected module dropdown.
F. Click the type dropdown and select a desired action. In this example, the EntityFadeOut action is selected.
Create A Trigger Based On When A User Clicks An Object
This guide provides instructions for setting up the NotificationCenterSubscribeEntityPicking trigger. In the sample app, the user clicks on the whale and the whale switches to the jump animation state.
The whale starts in the idle animation state.
When the user clicks on the whale, the whale switches to the jump animation state.
In this example, a trigger area is created on a 3D model and when the user clicks on the trigger area, an action causes the 3D model to play an animation. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example creates a trigger area over a 3D model, a simple box shape collider is used. The entity does not have a RigidBody component. To create the animation state graph, right-click in the Assets window and select New Asset > Anim State Graph.
A. Right-click on the graph and select Add New State. Rename the animation states. In this example, the Initial State animation has been changed to Idle. Confirm that the checkbox for loop is enabled.
B. In this example, the new animation state has been changed to Jump. Confirm that the checkbox for loop is disabled.
C. Close the animation state graph by clicking the X.
A. Select the 3D model in the Hierarchy. Click the "Add Component" button. Select Physics > Collision to add a Collision component.
B. Click the "Add Component" button. Select Animation > Anim to add the Anim component. Add the animation state graph that was created to the State Graph field.
C. Add an idle animation to the Idle animation state.
D. Add a jump animation to the Jump animation state.
E. Resize the collider to the desired size. In this example, the Half Extents field has been set to (.5, .5, 2) for X, Y, Z.
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select NotificationCenterSubscribeEntityPicking trigger.
E. Click "+" beside the selected module dropdown.
F. Click the type dropdown and select a desired action. In this example, the EntityPlayAnimation action is selected. For the EntityPlayAnimation action to work, the name of the animation state that gets played needs to be added to the animate state to play field. In this example, the animation state name Jump
is added. The model that will be animated also needs to be added to the pick up specify execution entity field.
An Action And Trigger Combination That Sends And Receives A Notification To An Object
This guide provides instructions for setting up the NotificationCenterPublish action and the NotificationCenterSubscribe trigger. In the sample app, every time the avatar enters the green trigger area, a notification is sent to the wall and the collider on the wall is toggled on/off. The wall is green when the avatar can pass through and red when the avatar can not pass through.
Before the avatar enters the green trigger area, the wall is red and the avatar can not pass through the wall.
Once the avatar enters the green trigger area, the green trigger sends a notification to the wall and the collider on the wall is disabled.
In this example, a trigger is created and when the avatar or other objects enters the trigger area, an action sends a notification to another object. The other object receives the notification via trigger, then initiates an action. Any object can be used as a trigger, as long as the object has a Collision component. Because this specific example creates an empty area that the avatar and other objects can pass through, a simple 3D box is used. The entity does not have a RigidBody component added. Right-click in the Hierarchy and select New Entity > 3D > Box.
A. In this example, the cube has been enlarged by setting the values for Scale to (1, 2, 1) for X, Y, Z.
B. Click the "Add Component" button. Select Physics > Collision to add a Collision component.
C. Resize the collider to the desired size. In this example, the Half Extents field has been set to (.5, 1, .5) for X, Y, Z.
D. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select a desired trigger. In this example, the EntitySubscribeTriggerEnter trigger is selected.
E. Click "+" beside the selected module dropdown.
F. Click the type dropdown and select NotificationCenterPublish action in the dropdown menu.
G. Add a name for this notification in the notification name to publish field. In this example, the ToggleWall name is added.
A. In this example, the object receiving the notification is a simple 3D cube that is used as a wall to prevent the avatar from moving forward. Any object can be used to receive notifications. Because the avatar will be colliding with this object, Collision and RigidBody components are added. Right-click in the Hierarchy and select New Entity > 3D > Box. The cube has been enlarged by setting the values for Scale to (.25, 1.75, 4.58) for X, Y, Z.
B. Click the "Add Component" button. Select Physics > Collision to add a Collision component. Click the "Add Component" button again and select Physics > Rigid Body to add the RigidBody component.
C. Resize the collider to the desired size. In this example, the Half Extents field has been set to (.15, 1, 2.3) for X, Y, Z.
D. Click the "EDIT VIVERSE EXTENSION" button to add the VIVERSE functionality.
A. Click the Select plugins text field and select TriggerAndAction in the dropdown menu.
B. Click "+" beside the Select a module and add dropdown.
C. Click "+" beside the selected module dropdown.
D. Click the type dropdown and select the NotificationCenterSubscribe trigger.
E. In the notification name to publish field, add the same name that was used in the NoticationCenterPublish trigger. In this example, the ToggleWall name is added.
F. Click "+" beside the selected module dropdown.
G. Click the type dropdown and select a desired action. In this example, the EntityToggleCollision action is selected.