This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
Landscape Tool
Sandworm
Using Editor Tools for Specific Tasks
Extending Editor Functionality
Built-in Node Types
Nodes
Objects
Effects
Decals
Light Sources
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

NodeTrigger Class

Warning
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScript (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.
Inherits from: Node

A trigger node is a zero-sized node that has no visual representation and fires callbacks when:

  • It is enabled/disabled (the enabled callback function is called).
  • Its transformation is changed (the position callback function is called).
The trigger node 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.

For example, to detect if some node has been enabled (for example, a world clutter node that renders nodes only around the camera has enabled it), the trigger node is added as a child to this node and fires the corresponding callback.

Creating a Trigger Node#

To create a trigger node, simply call the NodeTrigger constructor and then add the node as a child to another node, for which callbacks should be fired.

Source code (UnigineScript)
#include <core/unigine.h>

int init() {
	
	NodeTrigger trigger;
	ObjectMeshStatic object;
	
	// create a mesh
	Mesh mesh = new Mesh();
	mesh.addBoxSurface("box_0", vec3(1.0f));
	// create a node (e.g. an instance of the ObjectMeshStatic class)
	object = new ObjectMeshStatic(mesh);
	// change material albedo color
    object.setMaterialParameterFloat4("albedo_color", vec4(1.0f, 0.0f, 0.0f, 1.0f), 0);
	// release script ownership
	node_remove(object);
	
	// create a trigger node
	trigger = new NodeTrigger();
	node_remove(trigger);
	// add it as a child to the static mesh
	object.addWorldChild(trigger);

	return 1;
}

Editing a Trigger Node#

Editing a trigger node includes implementing and specifying the enabled and position callbacks that are fired on enabling or positioning the trigger node correspondingly.

The callback functions can be set by identifiers of the callback functions or by their names:

  1. setEnabledCallback() and setPositionCallback() receive identifiers of the callback functions. Wherein the callback function must receive at least 1 argument of the Node type. In addition, it can also take another 2 arguments of any type.
  2. setEnabledCallbackName() and setPositionCallbackName() receive names of the callback functions implemented in the world script. In this case, the callback function can receive no arguments or 1 argument of the Node or NodeTrigger type.
    Notice
    These methods allow for setting callbacks with 0 or 1 argument only. To set callbacks with additional arguments, use setEnabledCallback()/setPositionCallback().

Setting the callback functions by their identifiers:

Source code (UnigineScript)
#include <core/unigine.h>

NodeTrigger trigger;

// the position callback
void position_callback(Node trigger) {
    log.message("Object position has been changed. New position is: %s\n", typeinfo(trigger.getWorldPosition()));
}
// the enabled callback
void enabled_callback(Node trigger) {
    log.message("The enabled flag is %d\n", trigger.isEnabled());
}

int init() {

	// create a trigger node
    trigger = new NodeTrigger();
    // set the enabled and position callbacks by their identifiers
	trigger.setEnabledCallback(functionid(enabled_callback));
	trigger.setPositionCallback(functionid(position_callback));

	return 1;
}

int update() {
	
	// change the enabled flag and the trigger position to fire callbacks
	float time = engine.game.getTime();
	Vec3 pos = Vec3(sin(time) * 2.0f, cos(time) * 2.0f, 0.0f);
	trigger.setEnabled(pos.x > 0.0f || pos.y > 0.0f ? 1 : 0);
	trigger.setWorldPosition(pos);
	
	return 1;
}

Setting the callback functions by their names:

Source code (UnigineScript)
#include <core/unigine.h>

NodeTrigger trigger;

// the position callback
void position_callback(NodeTrigger trigger) {
    log.message("Object position has been changed. New position is: %s\n", typeinfo(trigger.getWorldPosition()));
}
// the enabled callback
void enabled_callback(NodeTrigger trigger) {
    log.message("The enabled flag is %d\n", trigger.isEnabled());
}

int init() {

	// create a trigger node
    trigger = new NodeTrigger();
    // set the enabled and position callbacks by their names
	trigger.setEnabledCallbackName("enabled_callback");
	trigger.setPositionCallbackName("position_callback");

	return 1;
}

int update() {
	
	// change the enabled flag and the trigger position to fire callbacks
	float time = engine.game.getTime();
	Vec3 pos = Vec3(sin(time) * 2.0f, cos(time) * 2.0f, 0.0f);
	trigger.setEnabled(pos.x > 0.0f || pos.y > 0.0f ? 1 : 0);
	trigger.setWorldPosition(pos);
	
	return 1;
}

See Also#

  • A C++ API sample <UnigineSDK>/source/samples/Api/Nodes/NodeTrigger
  • A C# API sample located in the <UnigineSDK>/source/csharp/samples/Api/Nodes/NodeTrigger folder

NodeTrigger Class

Members


static NodeTrigger ( ) #

Constructor. Creates a new trigger node.

void setEnabledCallback ( int func ) #

Sets a callback function to be fired when the trigger node is enabled. The callback function must receive a Node as its first argument. In addition, it can also take 2 arguments of any type.
Source code (UnigineScript)
// implement the enabled callback
void enabled_callback(Node node) {
	log.message("The enabled flag is %d\n", node.isEnabled());
}

NodeTrigger trigger;

int init() {

	// create a trigger node
	trigger = new NodeTrigger();
	// set the enabled callback to be fired when the node is enabled/disabled
	trigger.setEnabledCallback(functionid(enabled_callback));
	
	return 1;
}

Arguments

  • int func - Callback function identifier.

void setEnabledCallbackName ( string name ) #

Sets a callback function to be fired when the trigger node is enabled. The callback function can take no arguments, a Node or a NodeTrigger.
Notice
The method allows for setting a callback with 0 or 1 argument only. To set the callback with additional arguments, use setEnabledCallback().
Source code (UnigineScript)
// implement the enabled callback
void enabled_callback(Node node) {
	log.message("The enabled flag is %d\n", node.isEnabled());
}

NodeTrigger trigger;

int init() {

	// create a trigger node
	trigger = new NodeTrigger();
	// set the enabled callback to be fired when the node is enabled/disabled
	trigger.setEnabledCallbackName("enabled_callback");
	
	return 1;
}

Arguments

  • string name - Name of the callback function implemented in the world script (UnigineScript side).

string getEnabledCallbackName ( ) #

Returns the name of callback function to be fired on enabling the trigger node. This callback function is set via setEnabledCallbackName().

Return value

Name of the callback function implemented in the world script (UnigineScript side).

void setPositionCallback ( int func ) #

Sets a callback function to be fired when the trigger node position has changed. The callback function must receive a Node as its first argument. In addition, it can also take 2 arguments of any type.
Source code (UnigineScript)
// implement the position callback
void position_callback(Node node) {
	log.message("A new position of the node is %s\n", typeinfo(node.getWorldPosition()));
}

NodeTrigger trigger;

int init() {

	// create a trigger node
	trigger = new NodeTrigger();
	// set the position callback to be fired when the node position is changed
	trigger.setPositionCallback(functionid(position_callback));
	
	return 1;
}

Arguments

  • int func - Callback function identifier.

void setPositionCallbackName ( string name ) #

Sets a callback function to be fired when the trigger node position has changed. The callback function can take no arguments or a Node or a NodeTrigger as the first argument.
Notice
The method allows for setting a callback with 0 or 1 argument only. To set the callback with additional arguments, use setPositionCallback().
Source code (UnigineScript)
// implement the position callback
void position_callback(Node node) {
	log.message("A new position of the node is %s\n", typeinfo(node.getWorldPosition()));
}

NodeTrigger trigger;

int init() {

	// create a trigger node
	trigger = new NodeTrigger();
	// set the position callback to be fired when the node position is changed
	trigger.setPositionCallbackName("position_callback");
	
	return 1;
}

Arguments

  • string name - Name of the callback function implemented in the world script (UnigineScript side).

string getPositionCallbackName ( ) #

Returns the name of callback function to be fired on changing the trigger node position. This function is set by using the setPositionCallbackName() function.

Return value

Name of the callback function implemented in the world script (UnigineScript side).
Last update: 2021-12-13
Build: ()