Understanding the Difference between OnCollisionEnter and OnTriggerEnter and Their Use Cases

Simon Pham
2 min readJun 24, 2023

--

Objective: This blog post aims to provide a comparison between OnCollisionEnter and OnTriggerEnter and help you determine when to use each in 3D game development.

Unity utilizes both OnCollisionEnter and OnTriggerEnter to detect collisions in game development, but there are differences between them.

OnCollisionEnter

OnCollisionEnter is called when a Collider/Rigidbody begins touching another Rigidbody/Collider, resulting in a “bounce-off” effect. Here’s an example:

When the purple cube makes contact with the blue cube, it pushes the other cube towards the bottom of the screen, and the console logs the message “Hit: Player.”

Note: For this type of collision to occur, both objects must have the “Is Trigger” property unchecked, and at least one of them must have a Rigidbody component attached. To detect this collision in your C# script, use the following code snippet:

private void OnCollisionEnter(Collision other)
{
Debug.Log("Hit: " + other.transform.name);
}

OnTriggerEnter

OnTriggerEnter is triggered when two GameObjects collide, creating a “pass-through” effect. Here’s an example:

The purple cube passes through the blue cube, and the console logs the message “Hit: Player.”

Note: For this type of collision to occur, both objects must have the “Is Trigger” property checked, and at least one of them must have a Rigidbody component attached. To detect this collision, use the following code snippet:

private void OnTriggerEnter(Collider other)
{
Debug.Log("Hit: " + other.transform.name);
}

So what are the use cases for each of these mentioned collisions?

OnCollisionEnter: This collision detection method is suitable for scenarios like car crashes or a character jumping on a platform (similar to Super Mario). It provides a realistic “bounce-off” effect.

OnTriggerEnter: This collision detection method is ideal for situations where a character passes through an item to collect it or when it enters a specific area in the game map. It allows for a “pass-through” effect.

--

--