Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


generateOnTriggerStayEvents

Whether the physics system sends OnTriggerStay events.
Read time 1 minuteLast updated 13 days ago

Definition

  • Type: Property
  • Namespace: UnityEngine
  • Assembly: UnityEngine.PhysicsModule
public static bool generateOnTriggerStayEvents { get; }

Remarks

Use this API to check whether
OnTriggerStay
events are enabled. This lets you add fallback paths to scripts that assume
OnTriggerStay
events are enabled.
Physics backends typically only send events when a collider enters or exits a trigger. Unity's physics system keeps track of which colliders remain inside a trigger, and generates an
OnTriggerStay
event.
However, generating
OnTriggerStay
events has some overhead. If you only make use of
OnTriggerEnter
and
OnTriggerExit
, you can turn this behaviour off in the Physics Settings. Disabling the generation of
OnTriggerStay
events provides performance benefits, especially for complex scenes.
Note: This property is read-only. To change this setting, use Project Settings in the Editor.

Examples

using UnityEngine;public class Example : MonoBehaviour{ void Start() { if (Physics.generateOnTriggerStayEvents) Debug.LogWarning("OnTriggerStay events are enabled. Consider disabling these from Physics Settings if you do not make use of OnTriggerStay, as it comes with performance gains."); }}