Skip to main content

Event Trigger

Event Trigger In Scene

An Event Trigger is a trigger zone in a scenario that executes an action when another object enters or exits it. Event Triggers control how the environment responds to the participant or other actors in the scene.

For example, you can use an Event Trigger to:

  • Reveal a roadblock when the player enters a specific zone.
  • Play text dialogue when the player approaches an intersection.
  • Switch a traffic light's signal when the player enters a junction.
  • Advance to the next scene when the player reaches the end zone.

Event Trigger Component​

Event Trigger Inspector

The EventTrigger component makes a trigger zone functional. While a collider defines the physical area, the component links that collider to the actions that occur when the zone is entered or exited.

Each EventTrigger instance requires a trigger collider to function. Without one, the component cannot detect interactions.

tip

If a single collider shape is not enough, you can build a compound collider by combining multiple colliders on child objects. In this case, the Event Trigger GameObject must also include a Rigidbody.

For an EventTrigger to interact with another object, two conditions must be met:

  • Collision layer — The EventTrigger's collider must be on a layer that is set to collide with the other object's layer in the collision matrix.
  • Rigidbody — At least one of the two objects (either the EventTrigger or the interacting object) must have a Rigidbody.
tip

Is Kinematic in Inspector

If you attach a Rigidbody directly to the Event Trigger, enable Is Kinematic so that it is not affected by gravity or external forces.

Quick Start​

gif of scooter player trigger event

The following steps set up a simple Event Trigger that activates when the player's scooter enters the trigger zone and enables (unhides) a roadblock GameObject in the scene:

1
Add an EventTrigger component

Add an EventTrigger component to an empty GameObject. Alternatively, drag the Event Trigger prefab (located at Assets/mobisim/Event/Prefab) into the scene.

2
Attach a collider

Attach a collider of your choice to the GameObject. In the Inspector window, enable Is Trigger on the collider.

Collider Inspector - Is Trigger

This collider defines the trigger zone. When the participant enters this collider, the Event Trigger activates.

3
Configure the layer

Configure the layer so that the Event Trigger's collider can interact with the player GameObject.

Event Trigger Layer

Set the trigger's layer to one configured to interact with the player's layer. You can verify or change which layers interact in the Physics Layer Collision Matrix under Project Settings.

Layer Collision Matrix

In the example above, the Default layer is configured to interact with the Mine layer (the player's layer), so the trigger can remain on Default. You can also create and assign a custom layer if needed.

4
Configure the EventTrigger's filter

Configure the EventTrigger's filter so that only the scooter pawn can activate it.

Configured Event Trigger Filter

In the Inspector window, set Filter Types to include Tag, Layer, and ScriptableTag. Set the condition operator (the small dropdown to the right of Filter Types) to And so that all conditions must be met, then configure the values as follows:

  • Tag → Mine
  • Layer → Mine
  • ScriptableTag → Scooter_Tag

With these settings, the trigger activates only when an object that has the Mine tag, is on the Mine layer, and carries the Scooter_Tag scriptable tag enters the collider.

5
Configure the On Enter Triggered event

Configure the On Enter Triggered UnityEvent to enable the roadblock when the trigger fires. Click the + button in the On Enter Triggered field, drag the roadblock GameObject into the event field, and select GameObject > SetActive(bool) from the dropdown. Enable the checkbox to make the roadblock appear when the trigger activates.

Configured On Enter Triggered

If the scene has no roadblock GameObject, add one: any solid object with a collider that blocks the road. Disable the roadblock in the Hierarchy window so it starts hidden.

6
(Optional) Enable Only Trigger Event Once

In the Inspector, enable the Only Trigger Event Once field. When this is enabled, the trigger fires only once.

This option is enabled by default when you add a new EventTrigger component, but it is disabled on the Event Trigger prefab.

7
(Optional) Attach the DataCollector component

Attach a DataCollector component to the same GameObject and enable it. This flags the Event Trigger for data collection.

You now have a simple, working Event Trigger that fires when the player's scooter enters the trigger collider and enables a roadblock in the scene.

Configuring the Event Trigger Component​

You can use the following properties to configure the EventTrigger component and its filter:

Event Trigger
Property
Description
On Enter Triggered
UnityEvent invoked when a collider enters and passes filters.
On Exit Triggered
UnityEvent invoked when a collider exits and passes filters.
Only Trigger Event Once
Whether the enter and exit UnityEvents should only invoke once. Enabled by default on a newly added component.
Filter Types
Defines which filtering criteria are applied. One or more filter types can be enabled simultaneously.
└Tag
Tag that the other GameObject must have to pass the Tag filter.
└Layer Mask
Layers that are allowed to trigger the event.
└GameObject
Specific GameObject reference required for the Object filter.
└ScriptableTags
Custom ScriptableTag(s) that the GameObject must have. The GameObject passes if it has any one of them.
Condition Operator
The unlabeled dropdown next to Filter Types. Defines how filters are evaluated when multiple filter types are enabled.

Filters​

The EventTrigger component relies on layers to control which objects can interact with its trigger zone. However, because different objects can share the same layer, layers alone may not be specific enough. Filters let you further restrict which objects can activate a trigger.

When a collision is registered, the EventTrigger checks the interacting object against its configured filters and invokes the corresponding event only when all requirements are met.

Use the Filter Types property in the Inspector window to define which criteria the trigger evaluates. One or more filter types can be enabled simultaneously.

The following options are available:

  • Nothing — No checks are run; any object that collides is accepted.
  • Everything — Enables all available filter types (whether the object passes depends on the condition operator).
  • Tag — Checks that the object has the specified Unity Tag.
  • Layer — Checks that the object is on one of the specified Layers.
  • Object — Checks that the object matches the specified GameObject reference.
  • ScriptableTag — Checks that the object carries one of the specified Scriptable Tags.
note

The property fields for Tag, Layer, Object, and ScriptableTag are only shown when their corresponding filter type is enabled.

info

If the entering collider belongs to a Rigidbody, the filters are checked against the Rigidbody's GameObject rather than the collider's own GameObject.

The condition operator dropdown next to Filter Types decides how the requirements are evaluated when multiple filter types are selected:

  • And — All enabled filter types must pass for the trigger to activate.
  • Or — The trigger activates if at least one enabled filter type passes.

Using Events​

The EventTrigger component provides two UnityEvents that you can configure in the Inspector window:

  • On Enter Triggered — invoked when another object enters the trigger zone.
  • On Exit Triggered — invoked when that object exits the trigger zone.

When Only Trigger Event Once is disabled, both events can be invoked multiple times. Enabling the Only Trigger Event Once checkbox causes the UnityEvents to remove themselves after firing once, making them one-off actions. The checkbox is enabled by default on a newly added component and on the variant prefabs, and disabled on the base Event Trigger prefab.

caution

With Only Trigger Event Once enabled, On Exit Triggered does not fire after On Enter Triggered has fired, because the exit event is only invoked while the enter event is still registered.

tip

Once a trigger has served its purpose, disable the trigger's collider or its entire GameObject to prevent unnecessary collision checks during the session. You can configure this directly in the On Enter Triggered or On Exit Triggered fields.

For example, configure On Enter Triggered to enable the roadblock and then disable the trigger in the same event.

Note that disabling the GameObject also disables any attached DataCollector, stopping data collection for that Event Trigger.

tip

The On Enter Triggered or On Exit Triggered event can also call another EventTrigger's methods (the dynamic TriggerEnterEvent and TriggerExitEvent, which receive the entering Collider). Use this to chain triggers together, so that one activation leads directly to another, or to remotely activate a different trigger elsewhere in the scene.

Event Trigger Variants​

The simulator provides variant prefabs for common scenario tasks. Each variant is preconfigured for a specific behavior, reducing setup time for frequently used interaction patterns.

All variant prefabs can be found under Assets > mobisim > Event > Prefab.