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.WorldTrigger Class

Inherits from: Node

World triggers fire callbacks when any nodes (colliders or not) get inside or outside of them. The trigger can detect a node of any type by its bounding box. The trigger reacts to all nodes (default behavior).

The callback function of World Trigger is actually executed only when the next engine function is called: that is, before updatePhysics() (in the current frame) or before update() (in the next frame) — whatever comes first.

Notice
If you have moved some nodes and want to get callbacks based on changed positions in the same frame, you need to call engine.world.updateSpatial() first.

See Also#

  • A C++ API sample located in the <UnigineSDK>/source/samples/Api/Nodes/WorldTrigger folder
  • A C# API sample located in the <UnigineSDK>/source/csharp/samples/Api/Nodes/WorldTrigger folder
  • A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/worlds/ folder:
    • trigger_00
    • trigger_01
    • trigger_02

WorldTrigger Class

Properties

string LeaveCallbackName#

The name of the callback function name to be fired on leaving the world trigger. this callback function is set via setLeaveCallbackName().
set
Sets a callback function to be fired when nodes are leaving the world trigger. Unlike setLeaveCallback(), this callback function accepts a node that left the world trigger and world trigger itself as arguments.
set value - Name of the callback function.

string EnterCallbackName#

The name of callback function to be fired on entering the world trigger. this callback function is set via setEnterCallbackName().
set
Sets a callback function to be fired when nodes are entering the world trigger. Unlike setEnterCallback(), this callback function accepts a node that entered the world trigger and world trigger itself as arguments.
set value - Name of the callback function.

int NumNodes#

The number of nodes contained in the world trigger.

vec3 Size#

The current dimensions of the world trigger.
set
Updates the current dimensions of the world trigger. The minimum size is vec3(0,0,0).
set value - Dimensions of the world trigger. If negative values are provided, 0 will be used instead of them.

bool Touch#

A value indicating if a touch mode is enabled for the trigger. with this mode on, the trigger will react to the node by partial contact. when set to off, the trigger reacts only if the whole bounding sphere/box gets inside or outside of it.
set
Sets a touch mode for the trigger. With this mode on, the trigger will react to the node by partial contact. When set to off, the trigger reacts only if the whole bounding sphere/box gets inside or outside of it. The default is 0.
set value - Touch mode flag: true to enable the touch mode, false to disable it.

Members


WorldTrigger ( vec3 size ) #

Constructor. Creates a new world trigger with given dimensions.

Arguments

  • vec3 size - Dimensions of the new world trigger. If negative values are provided, 0 will be used instead of them.

IntPtr AddEnterCallback ( EnterDelegate func ) #

Adds a callback function to be fired when a node enters the world trigger. The callback function must receive a Node 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 enter callback
        void enter_callback(Node node)
        {
			Log.Message("\nA node named {0} has entered the trigger\n", node.Name);
        }

		WorldTrigger trigger;
		
        public override bool Init()
        {
            // create a world trigger
            trigger = new WorldTrigger(new vec3(3.0f));
            // add the enter callback to be fired when a node enters the world trigger
            trigger.AddEnterCallback(enter_callback);

            return true;
        }
	}
}

Arguments

  • EnterDelegate func - Callback function with the following signature: void EnterDelegate(Node node)

Return value

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

bool RemoveEnterCallback ( IntPtr id ) #

Removes the specified callback from the list of enter callbacks.

Arguments

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

Return value

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

void ClearEnterCallbacks ( ) #

Clears all added enter callbacks.

IntPtr AddLeaveCallback ( LeaveDelegate func ) #

Adds a callback function to be fired when a node leaves the world trigger. The callback function must receive a Node 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 leave callback
        void leave_callback(Node node)
        {
			Log.Message("\nA node named {0} has left the trigger\n", node.getName());
        }

		WorldTrigger trigger;
		
        public override bool Init()
        {
            // create a world trigger
            trigger = new WorldTrigger(new vec3(3.0f));
            // add the leave callback to be fired when a node leaves the world trigger
            trigger.AddLeaveCallback(leave_callback);

            return 1;
        }
	}
}

Arguments

  • LeaveDelegate func - Callback function with the following signature: void LeaveDelegate(Node node)

Return value

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

bool RemoveLeaveCallback ( IntPtr id ) #

Removes the specified callback from the list of leave callbacks.

Arguments

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

Return value

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

void ClearLeaveCallbacks ( ) #

Clears all added leave callbacks.

Node GetNode ( int num ) #

Returns a specified node contained in the world trigger.
Source code (C#)
using Unigine;

namespace UnigineApp
{
	class AppWorldLogic : WorldLogic
	{
		WorldTrigger trigger;

		public override bool Init()
		{
			// create a world trigger
            trigger = new WorldTrigger(new vec3(3.0f));

			return true;
		}

		public override bool Update()
		{
			// press the i key to get the info about nodes inside the trigger
			if (trigger != null && Input.IsKeyDown(Input.KEY.I))
			{
				//get the number of nodes inside the trigger
				int numNodes = trigger.NumNodes;
				Unigine.Log.Message("The number of nodes inside the trigger is " + numNodes + "\n");

				//loop through all nodes to print their names and types
				for (int i = 0; i < numNodes; i++)
				{
					Node node = trigger.GetNode(i); 
					Unigine.Log.Message("The type of the " + node.Name + " node is " + node.Type + "\n");
				}
			}

			return true;
		}
	}
}

Arguments

  • int num - Node number in range from 0 to the total number of nodes.

Return value

Node pointer.

Node[] GetNodes ( ) #

Gets nodes contained in the trigger.

Arguments

    static int type ( ) #

    Returns the type of the node.

    Return value

    World type identifier.
    Last update: 2021-04-29
    Build: ()