Collision vs Trigger in Unity: Key Differences and When to Use Each
Collision occurs when two objects with colliders physically hit each other and at least one has a Rigidbody component, triggering OnCollision events. A Trigger is a collider set as a trigger that detects when objects enter or exit its area without physical collision, firing OnTrigger events instead.Quick Comparison
This table summarizes the main differences between Collision and Trigger in Unity.
| Aspect | Collision | Trigger |
|---|---|---|
| Collider Setting | Collider is NOT set as trigger | Collider is set as trigger |
| Physical Interaction | Objects physically collide and respond | No physical collision, objects pass through |
| Required Components | At least one object has Rigidbody | At least one object has Rigidbody |
| Event Methods | OnCollisionEnter/Stay/Exit | OnTriggerEnter/Stay/Exit |
| Use Case | Detect physical impacts, blocking | Detect presence or area entry without blocking |
| Performance | More costly due to physics response | Less costly, no physics response |
Key Differences
Collision events happen when two colliders physically hit each other and at least one has a Rigidbody component. Unity's physics engine calculates the impact, causing objects to bounce, stop, or slide depending on physics materials and forces. The event methods OnCollisionEnter, OnCollisionStay, and OnCollisionExit provide detailed collision data like contact points and impact force.
In contrast, a Trigger collider is a special collider marked as a trigger. It does not cause physical collisions but detects when other colliders enter, stay, or exit its volume. The methods OnTriggerEnter, OnTriggerStay, and OnTriggerExit are called without any physics response, making triggers ideal for detecting zones, pickups, or checkpoints.
Triggers require at least one Rigidbody on either collider to detect events, but they do not affect object movement. Collisions require Rigidbody(s) to respond physically. Choosing between them depends on whether you want physical interaction or just detection.
Code Comparison
Here is an example of handling a physical collision between two objects using OnCollisionEnter.
using UnityEngine; public class CollisionExample : MonoBehaviour { private void OnCollisionEnter(Collision collision) { Debug.Log("Collision detected with " + collision.gameObject.name); } }
Trigger Equivalent
This example shows how to detect when an object enters a trigger area using OnTriggerEnter.
using UnityEngine; public class TriggerExample : MonoBehaviour { private void OnTriggerEnter(Collider other) { Debug.Log("Trigger entered by " + other.gameObject.name); } }
When to Use Which
Choose Collision when you need objects to physically interact, like characters bumping into walls or projectiles hitting targets. Collisions handle physics responses and are essential for realistic movement and blocking.
Choose Trigger when you want to detect presence without blocking movement, such as entering a safe zone, picking up items, or activating events. Triggers are lighter on performance and do not affect physics simulation.
Key Takeaways
Collision for physical impacts and responses between objects with Rigidbody.Trigger to detect when objects enter or exit an area without physical collision.OnCollisionEnter/Stay/Exit, triggers use OnTriggerEnter/Stay/Exit.