Reactions and interaction logic


In addition to this section, learn more about Interaction Requirements and Snapping.


"Reactions", allows custom logic to be added to events in an application. Using this feature, a light can be turned on or off when a dial is turned, without having to write any code. Customised reactions can be derived if needed, but a few useful ones are provided out of the box:

  • an interactable object is snapped or unsnapped
  • an interactable object is engaged or dropped
  • a PushButton is pressed
  • a Switch is pushed

Some actions which can be performed:

  • enable and/or disable a list of GameObjects
  • toggle a GameObject on or off
  • play a sound
  • set an animation bool or trigger
  • set image fill (for a dial)

How to implement

Reactions are added in specific places so that the Immerse SDK can discover them at runtime. Core reaction components can be used, or customised components can be created from base classes. Note - there are specific base classes for specific types of components.

OnEnable and OnDisable objects

The simplest way to write custom logic is to create a simple script that performs its action using OnEnable and OnDisable. These are Unity component methods that will be called when the object is enabled or disabled.

Add the script to a new GameObject, and then add a reaction that will enable/disable this object as required.

OnSnapped reactions

These reactions execute logic when an object is snapped or unsnapped. All reactions derive from the OnSnappedReaction abstract class.

Add OnSnapped reactions to:

  • the Snap Target they relate to, or
  • the TransformSync object directly if they relate to the origin snap target.

Some of the components the SDK provides are:

OnEnaged reactions

These reactions relate to engagement, which allows logic to be executed when an object is grabbed or dropped, or in some cases, like the dial, whenever the value changes. All these reactions derive from the EngageableObjectReaction abstract class.

Add OnEnaged reactions to the object with the EngageableObject class on (such as Dial or Pickup).

Some of the components the SDK provides are:

PushButton and Switch

PushButton and Switch have their own set of reactions because they do not use TransformSync for state management and work slightly differently. They derive from PushButtonReaction class and ToggleSwitchReaction class respectively.

Add reactions to the object with the PushButton or Switch component on.

Some of the components the SDK provides are:

Updated 4 months ago

Reactions and interaction logic

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.