This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
How To
Basics
Rendering
Professional (SIM)
UnigineEditor
Interface Overview
Assets Workflow
Version Control
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Lighting
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
Materials and Shaders
Rebuilding the Engine Tools
GUI
Double Precision Coordinates
API Reference
Animations-Related Classes
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
VR-Related Classes
Content Creation
Content Optimization
Materials
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Video Tutorial: How To Use Node Triggers to Detect Changes in Node States

Notice
Subtitles are available for each tutorial in English, Russian, and Chinese.
Warning
The tutorial is created with SDK version 2.18. Not applicable for earlier versions.


Node Trigger is a node without a visual representation that fires callbacks when it is enabled/disabled or its transformation is changed.

The component code displayed in this video is provided below for your convenience:

Trigger.cs
using System.Collections;
using System.Collections.Generic;
using Unigine;

[Component(PropertyGuid = "AUTOGENERATED_GUID")] // <-- this line is generated automatically for a new component
public class Trigger : Component
{
	public AssetLink explosion;

	void position_event_handler(NodeTrigger trigger)
	{
		Log.Message("Object position has been changed. New position is: {0}\n\n", trigger.WorldPosition.ToString());
	}


	void enabled_event_handler(NodeTrigger trigger)
	{
		SoundSource soundSource = new SoundSource(explosion.Path);
		soundSource.WorldPosition = trigger.WorldPosition;
		soundSource.MaxDistance = 100.0f;
		soundSource.Play();
	}

	NodeTrigger nodeTrigger;
	void Init()
	{
		// Cast Node to NodeTrigger
		nodeTrigger = node as NodeTrigger;

		if(nodeTrigger){
			// Subscribe for Enabled and Position events to perform actions 
			// when a node is enabled/disabled or changes its position
			nodeTrigger.EventEnabled.Connect(enabled_event_handler);
			nodeTrigger.EventPosition.Connect(position_event_handler);
		}
	}
	
	void Update()
	{
		// Disable the parent object when it is below the plane z = 2.0f
		if(node.Parent.WorldPosition.z < 2.0f)
			node.Parent.Enabled = false;
		
	}
}

To enable the visualizer and display console messages, add the following code in the Init() method in AppWorldLogic.cpp or any suitable component:

Source code (C#)
// Enable Visualizer
Visualizer.Enabled = true;

// Display console messages on the screen
Unigine.Console.Onscreen = true;
Last update: 2025-03-04
Build: ()