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 events are enabled. This lets you add fallback paths to scripts that assume events are enabled.
OnTriggerStayOnTriggerStayPhysics 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 event.
OnTriggerStayHowever, generating events has some overhead. If you only make use of and , you can turn this behaviour off in the Physics Settings. Disabling the generation of events provides performance benefits, especially for complex scenes.
OnTriggerStayOnTriggerEnterOnTriggerExitOnTriggerStayNote: 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."); }}