OnCollisionEnter vs. OnTriggerEnter and when to use them

Come together.

This is just a very brief article to help you distinguish between OnCollisionEnter and OnTriggerEnter. The two are triggered by the same circumstance: the interaction between two colliders. But they report different facts about that event.

OnTriggerEnter requires the Collider component of the object to have “is trigger” enabled. When this option is selected, Unity will ignore physics for this object. When this object’s collider box (now a trigger box) touches another collider, it returns the other object in the collision to OnTriggerEnter. You can use this information in script to create an infinite range of conditional events.

When the object’s collider encounters another collider, OnCollisionEnter returns the Collision class. The Unity physics engine calculates a number of qualities, such as contact points, velocity, impulse, etc. and stores those as properties within the Collision class. This is useful if you’re simulating detailed physical interactions.

In short: OnTriggerEnter is for non-physics-calculating interactions between colliders. OnCollisionEnter is for physics-calculating interactions between colliders.

In the next article, we’ll go over script communication in Unity using GetComponent.

--

--

--

Unity Developer / Game Developer / Artist / Problem Solver

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Getting Started With the Git Command Line Editor — Git Bash

Storytelling: my first client project as a tech grad

Victory!

API Gateway Gets a Second Version

Python Tutorials — part 1 — Basics

Outsource Software Development

Azure DevOps Multi-Stage Pipelines

The ~magic~ of BCrypt in Rails

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Micha Davis

Micha Davis

Unity Developer / Game Developer / Artist / Problem Solver

More from Medium

My journey becoming a Unity game developer: Sleeping Guard Interaction-Player NavMesh movement…

Cleaning up the Homing Missile code

Day 95: Pushing Objects in Unity to Complete Puzzles

Why you should use Unity’s new input system