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 Physical Triggers to Catch Physical Objects

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.


Physical Trigger is a volume that fires callbacks when an object with a physical body and a shape gets inside or outside of it.

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 Physical : Component
{
	vec4 color;

	void enter_event_handler(Body body)
	{
		// Remember the material's color and set it to black
		color = body.Object.GetMaterialInherit(0).GetParameterFloat4("albedo_color");
		body.Object.GetMaterialInherit(0).SetParameterFloat4("albedo_color", vec4.BLACK);
	}

	void leave_event_handler(Body body)
	{
		// Restore the previous material's color
		body.Object.GetMaterialInherit(0).SetParameterFloat4("albedo_color", color);
	}

	PhysicalTrigger physicalTrigger;
	void Init()
	{
		// Cast Node to PhysicalTrigger
		physicalTrigger = node as PhysicalTrigger;

		if(physicalTrigger){
			// Subscribe for Enter and Leave events to perform actions 
			// when a body enters or leaves the trigger
			physicalTrigger.EventEnter.Connect(enter_event_handler);
			physicalTrigger.EventLeave.Connect(leave_event_handler);
		}
		
	}
	
	void Update()
	{
		// Render the trigger's volume
		Visualizer.RenderNodeBoundSphere(node, vec4.BLUE);
		
	}
}

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

Source code (C#)
// Enable Visualizer
Visualizer.Enabled = true;
Last update: 2025-03-04
Build: ()