> For the complete documentation index, see [llms.txt](https://docs.viverse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.viverse.com/playcanvas-toolkit/building-with-playcanvas-toolkit/triggers.md).

# Triggers

***

## About

Triggers is a fundamental part of VIVERSE Framework, allowing creators to handle a wide range of player- and game-specific events without writing a single line of code! Whenever Player interacts with some Entity — be it a click, or collision, or seat taking — a corresponding event is generated, and any Trigger, associated with this event, also gets activated.

## Usage

Triggers don't do anything on their own — they're typically paired with [Actions](/playcanvas-toolkit/building-with-playcanvas-toolkit/actions.md) or [Custom Scripts](/playcanvas-toolkit/building-with-playcanvas-toolkit/custom-scripts.md) to produce desired effects of their activations.

Here is a simple example of using Trigger with an Action:

{% columns %}
{% column width="66.66666666666666%" %}
{% stepper %}
{% step %}

### Setup Trigger

* Create a new empty Entity in your Scene
* Add **3D > Render Component** of type `Box`. Your Entity should be visible in your Scene now
* Add **Physics > Collision Component** of type `Box` as well. Adjust its params if necessary
* Click **Add Viverse Component** button and select **Rule > Trigger**. The `viverseTrigger` script will be added to your Entity
* In Trigger Component, add a new entry to the Trigger List, by entering 1
* Leave Trigger type at `OnSelect` (default), and give it a unique `Name`, for example `box.clicked`
  {% endstep %}

{% step %}

### Setup Action

* With your Entity selected, click **Add Viverse Component** button once again, and select **Rule > Action**. The `viverseAction` script will be added to your Entity
* In Action Component, add a new entry to the Action List, by entering 1
* Populate `Trigger / Condition` field with your Trigger Name, which is `box.clicked` in our case
* Leave all other params at their defaults - `ToggleEntities`, `Toggle`, `Self`&#x20;
  {% endstep %}

{% step %}

### Test and verify

* Now we can test our Trigger / Action pair!
* Launch your Scene in a new tab, walk towards white box Entity and click it
* If you set up everything correctly — the Entity should disappear on your click
  {% endstep %}
  {% endstepper %}
  {% endcolumn %}

{% column width="33.33333333333334%" %}

<figure><img src="/files/Y7sbAq2xmMXvq1YsVkPH" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/e8na4jAreOP0yBonIBDs" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Od2EZpkqOiykWqQ3JTgL" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/S57kjvmykETaPFWrMdww" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/fHQQQpZuuKgNl94J8h3w" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/HQjPHg6q66FwmRhiSrv6" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

{% hint style="info" %}
It's not really necessary to have both **Trigger** and **Action** Components on the same Entity! For the purpose of your experience you can have as many Entities as you like, each with its own Trigger or Action, or a combination of those.

The only important rule is that Trigger's `Name` param should match an Action's `Trigger / Condition` one if you want them to be linked together
{% endhint %}

## Reference

***

{% columns %}
{% column width="25%" %}
`OnSelect`<br>
{% endcolumn %}

{% column width="50%" %}
Activates when the Player points and clicks on this Trigger. Requires **Collision Component** to be attached to the Entity
{% endcolumn %}

{% column width="24.999999999999986%" %}

<figure><img src="/files/EcrulVIO8UqP4TVj8dLc" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

***

{% columns %}
{% column width="25%" %}
`OnCollision`<br>
{% endcolumn %}

{% column width="50%" %}
Activates when another **Rigidbody** interacts with this Trigger. Supported interactions:

* `TriggerEnter` / `TriggerLeave` \
  Requires **Collision Component** to be attached
* `CollisionStart` / `CollisionEnd` \
  Requires both **Collision** and **Rigidbody Components**

You can allow interactions with only the Player and / or some Entity with specific Tag. See **Collision Filter** for available options
{% endcolumn %}

{% column width="24.999999999999986%" %}

<figure><img src="/files/kqLuUe3KIOpTXXn54HXd" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/KhvA8EbiRaNvhCGFWM83" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

***

{% columns %}
{% column width="25%" %}
`OnAnimation`<br>
{% endcolumn %}

{% column width="50%" %}
Activates when animation state changes for this Trigger entity. Requires **Animation Component** to be attached. Supported animation events:

* `Start` / `End` / `CustomEvent`
  {% endcolumn %}

{% column width="24.999999999999986%" %}

<figure><img src="/files/zTgxPlBAQvv0Oz2FR9tg" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

***

{% columns %}
{% column width="25%" %}
`On`\
`SeatState`\
`Changed`<br>
{% endcolumn %}

{% column width="50%" %}
Activates when this Seat Entity changes its state. Works in tandem with **Seat Component**, therefore requires **viverseSeat** script to be attached to this Entity. Supported events:

* `Occupied` / `Vacated`
  {% endcolumn %}

{% column width="24.999999999999986%" %}

<figure><img src="/files/4K9JOQkSZzkQSbD41uFb" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

***

{% columns %}
{% column width="25%" %}
`On`\
`Notification`\
`Event`<br>
{% endcolumn %}

{% column width="50%" %}
Activates when another Entity with **Action Component** fires `PublishNotification` event with particular `Event Name` matching the one in this Trigger. You can use it to send / receive custom Notification Events between different Entities in your Scene
{% endcolumn %}

{% column width="24.999999999999986%" %}

<figure><img src="/files/GQxv4FSS3ABxmEGixkfm" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

***

{% columns %}
{% column width="25%" %}
`On`\
`Action`\
`Executing`<br>
{% endcolumn %}

{% column width="50%" %}
Activates when another Entity with **Action Component** starts executing an Action with a given `Action Name`. You can use it to sequentially chain multiple Triggers and Actions together, for example `Trigger A` → `Action A` → `Trigger B` → `Action B`
{% endcolumn %}

{% column width="24.999999999999986%" %}

<figure><img src="/files/zTgxPlBAQvv0Oz2FR9tg" alt=""><figcaption></figcaption></figure>
{% endcolumn %}
{% endcolumns %}

***


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.viverse.com/playcanvas-toolkit/building-with-playcanvas-toolkit/triggers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
