0
0
Unityframework~10 mins

OnCollisionEnter2D and OnTriggerEnter2D in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - OnCollisionEnter2D and OnTriggerEnter2D
Object A moves
Collision or Trigger detected?
Yes No
Is Collider Trigger?
Call OnTriggerEnter2D
Execute collision/trigger response
When two objects touch, Unity checks if the collider is a trigger or not, then calls the matching method to handle the event.
Execution Sample
Unity
void OnCollisionEnter2D(Collision2D collision) {
    Debug.Log("Collision with " + collision.gameObject.name);
}

void OnTriggerEnter2D(Collider2D other) {
    Debug.Log("Trigger with " + other.gameObject.name);
}
This code logs a message when the object collides or triggers with another object.
Execution Table
StepEvent TypeCollider Trigger?Method CalledLogged Output
1Object A touches Object BNoOnCollisionEnter2DCollision with ObjectB
2Object A enters Object C's trigger areaYesOnTriggerEnter2DTrigger with ObjectC
3Object A moves without touchingN/ANoneNo output
💡 Execution stops when no collision or trigger event occurs.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3
collision.gameObject.namenullObjectBObjectBObjectB
other.gameObject.namenullnullObjectCObjectC
Logged OutputemptyCollision with ObjectBTrigger with ObjectCNo output
Key Moments - 3 Insights
Why does OnTriggerEnter2D get called instead of OnCollisionEnter2D?
Because the collider involved has its 'Is Trigger' property checked, Unity calls OnTriggerEnter2D (see execution_table row 2).
What happens if two colliders touch but neither is a trigger?
OnCollisionEnter2D is called to handle the physical collision (see execution_table row 1).
Why is there no output when objects don't touch or enter triggers?
Because neither collision nor trigger events occur, so no methods are called (see execution_table row 3).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what method is called when Object A touches Object B and the collider is not a trigger?
AUpdate
BOnCollisionEnter2D
COnTriggerEnter2D
DStart
💡 Hint
Check execution_table row 1 under 'Method Called'
At which step does OnTriggerEnter2D get called?
AStep 2
BStep 1
CStep 3
DNever
💡 Hint
Look at execution_table row 2 for 'Method Called'
If Object C's collider was not set as a trigger, what method would be called when Object A touches it?
AOnTriggerEnter2D
BNo method called
COnCollisionEnter2D
DOnCollisionExit2D
💡 Hint
Recall that OnCollisionEnter2D is called when colliders are not triggers (see key_moments answer 2)
Concept Snapshot
OnCollisionEnter2D and OnTriggerEnter2D are Unity event methods.
OnCollisionEnter2D runs when two colliders physically collide (Is Trigger unchecked).
OnTriggerEnter2D runs when an object enters a trigger collider (Is Trigger checked).
Use these to detect and respond to collisions or trigger events in 2D games.
Full Transcript
In Unity 2D, when two objects touch, the engine checks if the collider is a trigger or not. If it is a trigger, OnTriggerEnter2D is called. If not, OnCollisionEnter2D is called. For example, if Object A touches Object B and neither collider is a trigger, OnCollisionEnter2D runs and logs a collision message. If Object A enters Object C's trigger area, OnTriggerEnter2D runs and logs a trigger message. If no collision or trigger happens, no method runs and no output is logged. This helps you respond differently to physical collisions and trigger zones in your game.