Skip to content

Component Icon Trigger Zone Component

Presentation

Intro

The Trigger Zone feature is designed to track objects passing through the light beam and to track when the beam is passing over them.

Trigger Zone Demo
The sphere turns green when passing through the beam

When attached to a Volumetric Light Beam (SD or HD), it will generate a 3D Mesh Collider or a 2D Polygon Collider (depending on the beam's Dimensions property). This Collider can be used to trigger other Colliders/RigidBodies to detect when they are inside the beam or not.

The colliders are only generated at runtime, meaning they won't be visible in the editor when not in playmode.

Inspector

Inspector Trigger Zone

Usage

The Trigger Zone component must be attached to a Volumetric Light Beam SD or HD. You can use this button at the bottom of the Volumetric Light Beam inspector.

Attach Trigger Zone to a light beam


Properties

Set Is Trigger

  • True: the Collider will be created as a convex trigger (it won't be physical). This is the most common and default behavior.
  • False: the Collider will be a regular collider (it will be physical). In case you want the beam to actually collide with objects...

Range Multiplier

Change the length of the Collider: used to make the Collider longer or shorter than the actual beam's Limit Range Max Distance.

  • Default value is 1.0: the exact same length than the beam.
  • For example, set 2.0 to make the Collider 2x longer than the beam.

Compatibility with other features

Realtime changes

The TriggerZone collider cannot be changed in realtime.
With the Track Changes During Playtime feature enabled (or with a HD Beam), if you animate a property which change the shape of the beam, the collider shape won't fit anymore.

(SD Beams) Dynamic Occlusion (Raycasting)

With 2D beams, the generated 2D Polygon Collider will be updated each time the dynamic occlusion has changed. This means it will take account of the occluded shape. Trigger Zone and Dynamic Occlusion

With 3D beams, for performance reasons, the collider will not be changed in realtime if an occluder blocks the beam (when the Dynamic Occlusion (Raycasting) feature is enabled). This means an Object could be triggered when located behind an occluder.

However, we provide the following script function you could ask to know where a Collider is located compared to an occluder:

DynamicOcclusionRaycasting.IsColliderHiddenByDynamicOccluder(Collider)

Here is an example of the kind of script you could attach to your Collider/Rigidbody to check if they pass through a beam:

[RequireComponent(typeof(Collider))]
public class CheckIfInsideBeam : MonoBehaviour
{
    bool m_IsInsideBeam = false;
    Collider m_Collider = null;

    void Start()
    {
        m_Collider = GetComponent<Collider>();
        Debug.Assert(m_Collider);
    }

    void FixedUpdate()
    {
        m_IsInsideBeam = false;
    }

    void OnTriggerStay(Collider trigger)
    {
        var dynamicOcclusion = trigger.GetComponent<VLB.DynamicOcclusionRaycasting>();

        if (dynamicOcclusion)
        {
            // This GameObject is inside the beam's TriggerZone.
            // Make sure it's not hidden by an occluder
            m_IsInsideBeam = !dynamicOcclusion.IsColliderHiddenByDynamicOccluder(m_Collider);
        }
        else
        {
            m_IsInsideBeam = true;
        }
    }

    void Update()
    {
        // Do whatever you want with the m_IsInsideBeam property here
    }
}

(SD Beams) Dynamic Occlusion (Depth Buffer)

The Dynamic Occlusion (Depth Buffer) feature computes the occlusion on the GPU, and so the Trigger Zone feature is not compatible with it.

(HD Beams) Volumetric Shadow

The Volumetric Shadow feature computes the shadow on the GPU, and so the Trigger Zone feature is not compatible with it.