Ben Traje
← Back to unity

Unity: OnTriggerEnter vs. OnCollisionEnter

11 Aug 26 (1mo ago)

The rule of thumb: Use OnCollisionEnter for physical impacts (bouncing, stopping, pushing) and OnTriggerEnter for spatial overlap (passing through).

The Golden Rule for Both

To fire either event:

  1. Both objects must have a Collider.
  2. At least one object must have a Rigidbody.
FeatureOnCollisionEnterOnTriggerEnter
Is Trigger SettingOFF on both colliders.ON on at least one collider.
Physical ReactionYes (objects block, bounce, or slide).No (objects pass directly through).
Performance CostHigher (calculates forces and contacts).Lower (only checks bounding box overlap).
Best ForWalls, bouncing projectiles, pushing crates.Collectibles, checkpoints, aggro/dead zones.

Quick Code Reference

// 1. Physical Impacts (Solid Colliders)
private void OnCollisionEnter(Collision collision)
{
    // Access impact force and exact contact points
    float force = collision.relativeVelocity.magnitude;
    Debug.Log($"Hit {collision.gameObject.name} with force: {force}");
}

// 2. Overlap Detection (Trigger Colliders)
private void OnTriggerEnter(Collider other)
{
    // 'other' is the specific collider that passed through the zone
    if (other.CompareTag("Player"))
    {
        Debug.Log("Player entered the zone!");
    }
}