0
0
UnityComparisonBeginner · 4 min read

Collision vs Trigger in Unity: Key Differences and When to Use Each

In Unity, a 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.

AspectCollisionTrigger
Collider SettingCollider is NOT set as triggerCollider is set as trigger
Physical InteractionObjects physically collide and respondNo physical collision, objects pass through
Required ComponentsAt least one object has RigidbodyAt least one object has Rigidbody
Event MethodsOnCollisionEnter/Stay/ExitOnTriggerEnter/Stay/Exit
Use CaseDetect physical impacts, blockingDetect presence or area entry without blocking
PerformanceMore costly due to physics responseLess 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.

csharp
using UnityEngine;

public class CollisionExample : MonoBehaviour
{
    private void OnCollisionEnter(Collision collision)
    {
        Debug.Log("Collision detected with " + collision.gameObject.name);
    }
}
Output
When the object collides physically with another, the console logs: "Collision detected with [OtherObjectName]"
↔️

Trigger Equivalent

This example shows how to detect when an object enters a trigger area using OnTriggerEnter.

csharp
using UnityEngine;

public class TriggerExample : MonoBehaviour
{
    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Trigger entered by " + other.gameObject.name);
    }
}
Output
When another collider enters the trigger zone, the console logs: "Trigger entered by [OtherObjectName]"
🎯

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

Use Collision for physical impacts and responses between objects with Rigidbody.
Use Trigger to detect when objects enter or exit an area without physical collision.
Collision events use OnCollisionEnter/Stay/Exit, triggers use OnTriggerEnter/Stay/Exit.
Triggers require colliders set as triggers and at least one Rigidbody; collisions require Rigidbody(s) for physics.
Choose based on whether you want physical blocking or just detection of presence.