Trigger
A trigger is a zero-sized node that has no visual representation and triggers events when:
- It is enabled/disabled (the Enabled event is triggered).
- Its transformation is changed (the Position event is triggered).
The Node Trigger node is usually added as a child node to another node, so that the handler functions were executed on the parent node enabling/disabling or transforming.
The Node Trigger can work with procedurally created World Clutter objects.
The Node Trigger can be used, for example, to play a sound of thunder when a lightning flashes: when the lightning node is enabled, the Enabled event handler that plays a sound is executed.
See also#
- The NodeTrigger class to edit triggers via API
- Video tutorial on How To Use Node Triggers to Detect Changes in Node States
Adding a Node Trigger#
To add a new Node Trigger via UnigineEditor do the following:
- Run UnigineEditor.
- On the Menu bar, click Create -> Logic -> Node Trigger.
- Place the Node Trigger in the world.
- Add the Node Trigger as a child to a node for which handlers should be executed: select the Node Trigger in the World Nodes Hierarchy window and drag it inside the required node.
Editing a Node Trigger#
To edit the Node Trigger, select it and go to the Node tab of the Parameters window.
Handling Events#
Editing a trigger node includes implementing and specifying the Enabled and Position event handlers that are executed on enabling or positioning the Trigger node correspondingly.
The event handler must receive at least 1 argument of the NodeTrigger type. In addition, it can also take another 2 arguments of any type.
The event handlers are set via pointers specified when subscribing to the following events: Enabled and Position.
// subscribe to the Enabled event when the trigger is enabled
nodeTrigger->getEventEnabled().connect(enabled_event_handler);
// subscribe to the Position event when the trigger's transformation is changed
nodeTrigger->getEventPosition().connect(position_event_handler);
// subscribe to the Enabled event when the trigger is enabled
nodeTrigger.EventEnabled.Connect(enabled_event_handler);
// subscribe to the Position event when the trigger's transformation is changed
nodeTrigger.EventPosition.Connect(position_event_handler);