Collisions and triggers
↑Quick overview
Section titled “Quick overview”A collision callback is for physical contact between colliders; a trigger callback is for overlap detection without normal collision response. The callbacks have distinct parameter types and prerequisites. This page covers Unity’s 3D physics; the 2D methods have a 2D suffix.
| Message | Use it for |
|---|---|
OnCollisionEnter(Collision collision) |
First frame of physical contact |
OnCollisionStay(Collision collision) |
Continued contact |
OnCollisionExit(Collision collision) |
Contact ended |
OnTriggerEnter(Collider other) |
Another collider entered a trigger |
OnTriggerStay(Collider other) |
Another collider remains in a trigger |
OnTriggerExit(Collider other) |
Another collider left a trigger |
Trigger example
Section titled “Trigger example”using UnityEngine;
public sealed class PickupZone : MonoBehaviour{ private void OnTriggerEnter(Collider other) { if (!other.CompareTag("Player")) return; Debug.Log("The player entered the pickup zone."); }}Add a collider to the zone, enable Is Trigger, and ensure the two objects meet Unity’s Rigidbody and collider requirements for a trigger event. Do not assume that any pair of colliders will generate a message.
Physical collision example
Section titled “Physical collision example”using UnityEngine;
public sealed class ImpactReport : MonoBehaviour{ private void OnCollisionEnter(Collision collision) { Debug.Log($"Hit {collision.gameObject.name}"); }}Troubleshooting checklist
Section titled “Troubleshooting checklist”- Check whether the colliders are enabled and set to Is Trigger for the intended behavior.
- Confirm the relevant object has a compatible Rigidbody and that the 3D APIs are being used with 3D components.
- Check the Layer Collision Matrix in Physics settings.
- Make sure the callback signature is exact, including parameter type and capitalization.
- Test a minimal two-object scene before adding complex gameplay rules.
Read Rigidbody and movement for the movement side of the interaction.
