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 Objects
Sound Objects
Pathfinding Objects
Players
Programming
Fundamentals
Setting Up Development Environment
Usage Examples
UnigineScript
C++
C#
UUSL (Unified UNIGINE Shader Language)
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
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.

Unigine.NodeTrigger Class

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 (C#)
using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
        private NodeTrigger trigger;
		private ObjectMeshStatic obj;

        public override bool Init()
        {
            // create a mesh
            Mesh mesh = new Mesh();
            mesh.AddBoxSurface("box_0", new vec3(1.0f));
			// create a node (e.g. an instance of the ObjectMeshStatic class)
            obj = new ObjectMeshStatic(mesh);
            obj.SetMaterial("mesh_base", "*");
            obj.SetMaterialParameterFloat4("albedo_color", new vec4(1.0f, 0.0f, 0.0f, 1.0f), 0);
            // create a trigger node
            trigger = new NodeTrigger();

			// add it as a child to the static mesh
            obj.AddWorldChild(trigger);

            return true;
        }
	}
}

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 function must receive at least 1 argument of the NodeTrigger type. In addition, it can also take another 2 arguments of any type.

The callback functions can be set by callback pointers or names:

  1. addEnabledCallback() and addPositionCallback() receive pointers to the callback functions.
  2. setEnabledCallbackName() and setPositionCallbackName() receive names of the callback functions implemented in the world script (on the UnigineScript side). In this case, the callback functions 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 addEnabledCallback()/addPositionCallback().

Setting the callback functions by pointers:

Source code (C#)
// AppWorldLogic.cs

using Unigine;

#if UNIGINE_DOUBLE
using Vec3 = Unigine.dvec3;
using Vec4 = Unigine.dvec4;
using Mat4 = Unigine.dmat4;
#else
using Vec3 = Unigine.vec3;
using Vec4 = Unigine.vec4;
using Mat4 = Unigine.mat4;
#endif

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
        private NodeTrigger trigger;
        private ObjectMeshStatic obj;
		
		// the position callback
        void position_callback(NodeTrigger trigger)
        {
            Log.Message("Object position has been changed. New position is: {0}\n", trigger.WorldPosition.ToString());
        }
		
		// the enabled callback
        void enabled_callback(NodeTrigger trigger)
        {
            Log.Message("The enabled flag is {0}\n", trigger.isEnabled());
        }

        public override bool Init()
        {
            // create a mesh
            Mesh mesh = new Mesh();
            mesh.addBoxSurface("box_0", new vec3(1.0f));
            // create a node (e.g. an instance of the ObjectMeshStatic class)
            obj = new ObjectMeshStatic(mesh);
            obj.setMaterial("mesh_base", "*");
            obj.setMaterialParameterFloat4("albedo_color", new vec4(1.0f, 0.0f, 0.0f, 1.0f), 0);

            // create a trigger node
            trigger = new NodeTrigger();

            // add it as a child to the static mesh
            obj.AddWorldChild(trigger);

            // add the enabled and position callbacks
			trigger.AddEnabledCallback(enabled_callback);
            trigger.AddPositionCallback(position_callback);

            return true;
        }
		
		public override bool Update()
		{
			float time = Game.Time;
            Vec3 pos = new Vec3(MathLib.Sin(time) * 2.0f, MathLib.Cos(time) * 2.0f, 0.0f);
            // change the enabled flag of the node
			obj.setEnabled(pos.x > 0.0f || pos.y > 0.0f ? 1 : 0);
			// change the node position
            obj.WorldPosition = pos;

			return true;
		}

	}
}

Setting the callback functions by their names:

  1. Implement the callback functions in the world script (on the UnigineScript side).
  2. Set the callback functions for the trigger node by using their names on the C# side (AppWorldLogic.cs).
Source code (UnigineScript)
// unigine_project.cpp

#include <core/unigine.h>

// the enabled callback
void enabled_callback(Node trigger) {
	
	log.message("Enabled flag is %d\n", trigger.isEnabled());
}
// the position callback
void position_callback(Node trigger) {
	
	log.message("The node position is %s\n", typeinfo(trigger.getWorldPosition()));
}

int init() {

	// some logic if required
	return 1;
}
Source code (C#)
using Unigine;

#if UNIGINE_DOUBLE
using Vec3 = Unigine.dvec3;
using Vec4 = Unigine.dvec4;
using Mat4 = Unigine.dmat4;
#else
using Vec3 = Unigine.vec3;
using Vec4 = Unigine.vec4;
using Mat4 = Unigine.mat4;
#endif

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
        private NodeTrigger trigger;

		public override bool Init()
		{
            // create a trigger node
            trigger = new NodeTrigger();

            // set the enabled and position callbacks
            trigger.EnabledCallbackName = "enabled_callback";
            trigger.PositionCallbackName = "position_callback";

			return true;
		}

		public override bool Update()
		{
			// change the enabled flag and the trigger position to fire callbacks
			float time = Game.Time;
            Vec3 pos = new Vec3(MathLib.Sin(time) * 2.0f, MathLib.Cos(time) * 2.0f, 0.0f);
            trigger.setEnabled(pos.x > 0.0f || pos.y > 0.0f ? 1 : 0);
            trigger.WorldPosition = pos;

			return true;
		}

	}
}

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


NodeTrigger ( ) #

Constructor. Creates a new trigger node.

IntPtr AddEnabledCallback ( EnabledDelegate func ) #

Sets a pointer to a callback to be fired when the trigger node is enabled. The callback function must receive a NodeTrigger as its first argument. In addition, it can also take 2 arguments of any type.
Source code (C#)
using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{	
		// implement the enabled callback
        void enabled_callback(NodeTrigger trigger)
        {
            Log.Message("The enabled flag is {0}\n", trigger.isEnabled());
        }

		NodeTrigger trigger;
		
        public override bool Init()
        {
            // create a trigger node
            trigger = new NodeTrigger();
            // add the enabled callback to be fired when the node is enabled/disabled
            trigger.AddEnabledCallback(enabled_callback);

            return 1;
        }
	}
}

Arguments

  • EnabledDelegate func - Callback function with the following signature: void EnabledDelegate(NodeTrigger trigger)

Return value

ID of the last added enabled callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool RemoveEnabledCallback ( IntPtr id ) #

Removes the specified callback from the list of enabled callbacks.

Arguments

  • IntPtr id - Enabled callback ID obtained when adding it.

Return value

True if the enabled callback with the given ID was removed successfully; otherwise false.

void ClearEnabledCallbacks ( ) #

Clears all added enabled callbacks.

void SetEnabledCallbackName ( string name ) #

Sets a callback function to be fired when the trigger node is enabled. The callback function must be implemented in the world script (on the UnigineScript side). 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().
On UnigineScript side:
Source code (UnigineScript)
// implement the enabled callback
void enabled_callback(Node node) {
	log.message("The enabled flag is %d\n", node.isEnabled());
}
On C# side:
Source code (C#)
using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{	

		NodeTrigger trigger;
		
        public override bool 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).

IntPtr AddPositionCallback ( PositionDelegate func ) #

Adds a pointer to a callback to be fired when the trigger node position has changed. The callback function must receive a NodeTrigger as its first argument. In addition, it can also take 2 arguments of any type.
Source code (C#)
using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{	
		// implement the position callback
        void position_callback(NodeTrigger trigger)
        {
            Log.Message("A new position of the node is {0}\n", trigger.getWorldPosition().ToString());
        }
		NodeTrigger trigger;
        public override bool Init()
        {
            // create a trigger node
            trigger = new NodeTrigger();
            // add the position callback to be fired when the node position is changed
            trigger.AddPositionCallback(position_callback);

            return 1;
        }
	}
}

Arguments

  • PositionDelegate func - Callback function with the following signature: void PositionDelegate(NodeTrigger trigger)

Return value

ID of the last added position callback, if the callback was added successfully; otherwise, nullptr. This ID can be used to remove this callback when necessary.

bool RemovePositionCallback ( IntPtr id ) #

Removes the specified callback from the list of position callbacks.

Arguments

  • IntPtr id - Position callback ID obtained when adding it.

Return value

True if the position callback with the given ID was removed successfully; otherwise false.

void ClearPositionCallbacks ( ) #

Clears all added position callbacks.

void SetPositionCallbackName ( string name ) #

Sets a callback function to be fired when the trigger node position has changed. The callback function must be implemented in the world script (on the UnigineScript side). 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 setPositionCallback().
On UnigineScript side:
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()));
}
On C# side:
Source code (C++)
using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{	
		NodeTrigger trigger;
		
        public override bool 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-04-29
Build: ()