Trigger
A trigger is a zero-sized node that has no visual representation and fires callbacks when:
- It is enabled/disabled (an enabled callback function is called).
- Its transformation is changed (a position callback function is called).
A Node Trigger is usually added as a child node to another node, so that the callbacks will be fired 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 callback function that plays a sound is called.
See also#
- The NodeTrigger class to edit triggers via API
- Videotutorial 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 callbacks should be fired: 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.
Setting Up Callbacks#
To add enabled/disabled or position callback, write a callback function that receives at least 1 argument of the NodeTrigger type. Then use use addEnabledCallback() / addPositionCallback() to specify the function to be called. See other methods of editing Node Trigger callbacks here.
// add the enabled and position callbacks
nodeTrigger->addEnabledCallback(MakeCallback(this, &enabled_callback));
nodeTrigger->addPositionCallback(MakeCallback(this, &position_callback));
// add the enabled and position callbacks
nodeTrigger.AddEnabledCallback(enabled_callback);
nodeTrigger.AddPositionCallback(position_callback);