Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

Physics.generateOnTriggerStayEvents

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static bool generateOnTriggerStayEvents;

Description

Whether the physics system sends OnTriggerStay events.

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.

            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."); } }