# Event Listeners

***

### EntitySubscribeTriggerEnter

This guide provides instructions for setting up the **EntitySubscribeTriggerEnter** trigger. In the sample app below, the trigger areas are outlined in blue. Once the avatar enters into the blue area, an action occurs.

| <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FGHp6TmIeJ29KsE25oIkU%2Fimage.png?alt=media&#x26;token=2e2bc1b3-aef9-4f3c-8358-b9d4ece79f3e" alt="" data-size="original"> | <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FQ1NOvxkWddYNW6ikg15g%2Fimage.png?alt=media&#x26;token=0b46cba9-827e-4c34-b7bc-76ee3f35d914" alt="" data-size="original"> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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 our example above, a trigger area is created. When the avatar enters the trigger area, an action is then initiated. Any object can be used as a trigger, as long as the object has a collision component. Our example uses a 3D box as the trigger area.

#### **Create a trigger for when an object enters an area**

{% stepper %}
{% step %}
**Create a trigger area**

A. Create a new **3D Box** entity.

B. Add a **Collision** component.

C. Adding a material is optional. A transparent material has been added so that the trigger area is visible in play mode.

D. Click the **Edit Viverse Extension** button.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2Frqf381n58a2jOpSaLR3C%2Fimage.png?alt=media&#x26;token=085edd3b-baa2-4984-a379-eecd783ff3e9" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Add the** *EntitySubscribeTriggerEnter* **trigger**

A. In the VIVERSE extension, select the **TriggerAndAction** plugin for the **Select plugins** dropdown.

B. Add a **Trigger** and select **EntitySubscribeTriggerEnter**.

C. Add **local-player** to the **tags to filter** field.

D. Add an **Action** and select **EntityEnableById.**

E. Add an object that will be enabled when the avatar enters the trigger area. The **golden\_coin** entity has been added to the **pick up specify execution entity**. The **golden\_coin** entity has also been disabled by default.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FfSaqFBuJTZFrYNrf55Ir%2Fimage.png?alt=media&#x26;token=18c62047-bf53-4505-b588-e58d1ec11a51" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### EntitySubscribeTriggerLeave

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.

| <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FG0uFhXyD1DfCzklne72B%2Fimage.png?alt=media&#x26;token=d5ab3f7b-ab19-4b4e-b12b-fdd089baa9d4" alt="" data-size="original"> | <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FH3yWTA4QmXgORPvyUelZ%2Fimage.png?alt=media&#x26;token=2811ff14-7206-41a2-8d90-584aebd5952c" alt="" data-size="original"> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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 leaves the trigger area, an action is initiated. Any object can be used as a trigger, as long as the object has a collision component. This example uses a 3D box as the trigger area.

#### **Create a trigger for when an object leaves an area**

{% stepper %}
{% step %}
**Create a trigger area**

A. Create a new **3D Box** entity.

B. Add a **Collision** component.

C. Adding a material is optional. A transparent material has been added so that the trigger area is visible in play mode.

D. Adding a material is optional. A transparent material has been added so that the trigger area is visible in play mode.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FreksZJ3HBIFfcgxo4wxu%2Fimage.png?alt=media&#x26;token=866e6d04-35e8-451d-ad8a-9c82d3161f6e" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Add the** *EntitySubscribeTriggerLeave* **trigger**

A. In the VIVERSE extension, select the **TriggerAndAction** plugin for the **Select plugins** dropdown.

B. Add a **Trigger** and select **EntitySubscribeTriggerLeave**.

C. Add **local-player** to the **tags to filter** field.

D. Add an **Action** and select **EntityDisableById.**

E. Add an object that will be disabled when the avatar leaves the trigger area. The **golden\_coin** entity has been added to the **pick up specify execution entity**.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FBGelezKghFUihjXt7bBN%2Fimage.png?alt=media&#x26;token=bc594c2d-c670-45bc-ab4e-abb5d607dea3" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### EntitySubscribeCollisionStart

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.

| <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FXfIYwc8MI9StnoAHKpJ7%2Fimage.png?alt=media&#x26;token=556f4b39-3851-4689-82fc-503dafe27542" alt="" data-size="original"> | <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FbNyHIxt4KW3LbODff8Rh%2Fimage.png?alt=media&#x26;token=6eaea07f-1fdd-4050-b96e-95bcdddec008" alt="" data-size="original"> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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 collides 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 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.

#### **Create a trigger for when an object collides with another object**

{% stepper %}
{% step %}
**Create the 3D object that the avatar will collide with**

A. Add 3D object to the scene.

B. Add a **Collision** component.

C. Add a **Rigidbody** component.

D. Click the **Edit Viverse Extension** button.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FyUahn1nxrVzHGmh2ZEXg%2Fimage.png?alt=media&#x26;token=76ed89a9-95cc-4d2b-93a5-d9fa3e906358" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Add the** *EntitySubscribeCollisionStart* **trigger**

A. In the VIVERSE extension, select the **TriggerAndAction** plugin for the **Select plugins** dropdown.

B. Add a **Trigger** and select **EntitySubscribeCollisionStart**.

C. Add **local-player** to the **tags to filter** field.

D. Add an **Action** and select **EntityDisable.**

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2F9AxeQOHsWqxfUxoPUIs4%2Fimage.png?alt=media&#x26;token=da6f52d7-1434-486b-8e45-1539435487b9" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### EntitySubscribeCollisionEnd&#x20;

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.

| <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2Fqqekbob0mNBRXxwprMLE%2Fimage.png?alt=media&#x26;token=e55b0c99-f943-42b7-a175-cb1fb25103a9" alt="" data-size="original"> | <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FYFBiUL1kayY3ApXS3o2f%2Fimage.png?alt=media&#x26;token=3ef48c26-b3b6-46f4-a553-87d5d28ca42b" alt="" data-size="original"> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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 can collide with, a **RigidBody** component needs to be added.

#### **Create A Trigger Based On When An Object Stops Colliding With Another Object**

{% stepper %}
{% step %}
**Create the 3D object that the avatar will collide with**

A. Add 3D object to the scene.

B. Add a **Collision** component.

C. Add a **Rigidbody** component.

D. Click the **Edit Viverse Extension** button.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FgLFsEq7puGvgi6XXsGMc%2Fimage.png?alt=media&#x26;token=9a315794-cd55-4d7d-aaa0-bf1148e18a3b" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Add the** *EntitySubscribeCollisionEnd* **trigger**

A. In the VIVERSE extension, select the **TriggerAndAction** plugin for the **Select plugins** dropdown.

B. Add a **Trigger** and select **EntitySubscribeCollisionEnd**.

C. Add **local-player** to the **tags to filter** field.

D. Add an **Action** and select **EntityFadeOut.**

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2Fvd5RJUKcFkd9CYbfBgmp%2Fimage.png?alt=media&#x26;token=be74627e-e5ee-48d0-9991-b1ede45ceb71" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### NotificationCenterSubscribeEntityPicking

This guide provides instructions for setting up the **NotificationCenterSubscribeEntityPicking** trigger. In the sample app, the user clicks on the buttons to show and hide the whale.

| <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2F2rQGRc2mv0rb5z8U4ERI%2Fimage.png?alt=media&#x26;token=bb5165b8-7bff-497a-b2eb-58d0d2708161" alt="" data-size="original"> | <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2F0PAD6L9mzlezcGv2mjAz%2Fimage.png?alt=media&#x26;token=3e6c383c-4bdd-40e7-8e7f-fae219a00cd6" alt="" data-size="original"> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The whale is visible.                                                                                                                                                                                                                                      | When the user clicks on the whale, the whale is disabled.                                                                                                                                                                                                  |

In this example, a trigger area is created on a button. When the user clicks on the trigger area, an action causes the 3D model to be disabled. Any object can be used as a trigger, as long as the object has a collision component.

#### **Create a trigger for when a user clicks an object**

{% stepper %}
{% step %}
**Create the 3D object that the user will click on**

A. Add a 3D object to the scene. In this example, a button is used, but any 3D object will work.

B. Add a **Collision** component.

C. Click the **Edit Viverse Extension** button.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2Frr7UxS9e0FXlTisCPTiH%2Fimage.png?alt=media&#x26;token=ea274f9d-b292-48f7-a94e-9ce409f29ea3" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Add the** *NotificationCenterSubscribeEntityPicking* **trigger**&#x20;

A. In the VIVERSE extension, select the **TriggerAndAction** plugin for the **Select plugins** dropdown.

B. Add a **Trigger** and select **NotificationCenterSubscribeEntityPicking**.

C. Add an **Action** and select **EntityDisable.** Add an object that will be disabled.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FsZvxTPtQm5ibZmW15WNj%2Fimage.png?alt=media&#x26;token=48e558c4-3b9b-4cad-908a-ecfc9e6a150a" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

### NotificationCenterPublish & NotificationCenterSubscribe

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.

| <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FH7VnDt63GNRAh7DpQHAr%2Fimage.png?alt=media&#x26;token=c451074f-ef52-4c51-949a-e9cc5ab4b20a" alt="" data-size="original"> | <img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FBzZPPmVakWlK4I0T5Pl1%2Fimage.png?alt=media&#x26;token=76f535a3-c926-4407-8c44-f3a179d7fbaa" alt="" data-size="original"> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 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 enters the trigger area, an action sends a notification to another object. The other object receives the notification via trigger, then initiates an action.&#x20;

#### **Action and Trigger combination to send a notification from one object to another**

{% stepper %}
{% step %}
**Create the 3D object that will send the notification**

A. Add a 3D object to the scene.

B. The **Collision** component is not required for **NotificationCenterPublish** action or **NotificationCenterSubscribe** trigger to work. The **Collision** component is required for the **EntitySubscribeTriggerEnter** trigger that will be used in this example.

C. Click the **Edit Viverse Extension** button.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FC1i0iwC32kgQ18vkUV6N%2Fimage.png?alt=media&#x26;token=32d13730-1dbc-4466-91eb-98570f807f00" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Add the** *NotificationCenterPublish* **action**

A. In the VIVERSE extension, select the **TriggerAndAction** plugin for the **Select plugins** dropdown.

B. Add a **Trigger** and select **EntitySubscribeTriggerEnter**.

C. Add **local-player** to the **tags to filter** field.

D. Add an **Action** and select **NotificationCenterPublish.**

E. Create a unique notification name and add it to the **notification name to publish** field. In this example, the notification is called **ToggleWall**.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FcAdO9WAhw6kUhfyZZkD3%2Fimage.png?alt=media&#x26;token=eeeadba0-6679-4dc4-aa75-7dbea1657177" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Create the 3D object that will receive the notification**

A. Add a 3D object to the scene.

B. The **Collision** component is not required for **NotificationCenterPublish** action or **NotificationCenterSubscribe** trigger to work. The **Collision** component is required for the **EntityToggleCollision** action that will be used in this example.

C. The **Rigidbody** component is not required for the **NotificationCenterPublish** action or **NotificationCenterSubscribe** trigger to work. The **Rigidbody** component is required for the **EntityToggleCollision** action that will be used in this example.

D. Click the **Edit Viverse Extension** button.

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2F1BQd94DYLDNUgoHNEXAA%2Fimage.png?alt=media&#x26;token=0b1c1206-f89e-48a2-99ce-c982040c0d8f" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}

{% step %}
**Add the** *NotificationCenterSubscribe* **action**

A. In the VIVERSE extension, select the **TriggerAndAction** plugin for the **Select plugins** dropdown.

B. Add a **Trigger** and select **NotificationCenterSubscribe**.

C. The same text that was added to the **notification name to publish** needs to be added to the **notification name to subscribe**.

D. Add an **Action** and select **EntityToggleCollision.**

<figure><img src="https://1140075852-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4pMiThqqrBzfvP8uy5am%2Fuploads%2FTftxcHfyYcUZHAqSj5BI%2Fimage.png?alt=media&#x26;token=7b659d5c-b407-408d-b462-fa75834eeca3" alt="" width="375"><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}
