0
0
Unityframework~10 mins

3D colliders in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - 3D colliders
Start: GameObject with Collider
Physics Engine checks collisions
Is Collider Trigger?
YesTrigger Event
OnTriggerEnter()
Collision Event
OnCollisionEnter() called
Respond to collision
End
This flow shows how Unity checks 3D colliders on objects, decides if they trigger events or collisions, and calls the right functions.
Execution Sample
Unity
void OnCollisionEnter(Collision collision) {
    Debug.Log("Hit " + collision.gameObject.name);
}

void OnTriggerEnter(Collider other) {
    Debug.Log("Triggered by " + other.gameObject.name);
}
This code runs when a 3D collider hits another or enters a trigger, printing the other object's name.
Execution Table
StepEvent TypeCollider StateFunction CalledOutput
1Collision detectedIsTrigger = falseOnCollisionEnterHit Enemy
2Trigger detectedIsTrigger = trueOnTriggerEnterTriggered by PowerUp
3Collision detectedIsTrigger = falseOnCollisionEnterHit Wall
4No collision or trigger---
💡 No more collisions or triggers detected, so no functions called.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
collision.gameObject.name-Enemy-WallWall
other.gameObject.name--PowerUp-PowerUp
Collider.IsTriggerfalsefalsetruefalsefalse
Key Moments - 2 Insights
Why does OnTriggerEnter run instead of OnCollisionEnter sometimes?
Because the collider's IsTrigger property is true, Unity calls OnTriggerEnter (see execution_table step 2). If IsTrigger is false, OnCollisionEnter runs (steps 1 and 3).
What happens if two colliders both have IsTrigger false and collide?
OnCollisionEnter is called on both objects involved in the collision, as shown in steps 1 and 3 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what function is called at step 2?
AUpdate
BOnCollisionEnter
COnTriggerEnter
DStart
💡 Hint
Check the 'Function Called' column at step 2 in the execution_table.
At which step does the collider have IsTrigger set to true?
AStep 2
BStep 1
CStep 3
DNo step
💡 Hint
Look at the 'Collider State' column in the execution_table and variable_tracker.
If the collider's IsTrigger was false at step 2, what would happen?
AOnTriggerEnter would still be called
BOnCollisionEnter would be called instead
CNo function would be called
DThe game would crash
💡 Hint
Refer to the key_moments explanation about IsTrigger property and function calls.
Concept Snapshot
3D Colliders in Unity detect physical contact.
If IsTrigger is false, OnCollisionEnter runs on contact.
If IsTrigger is true, OnTriggerEnter runs when overlapping.
Use these to respond to hits or triggers in your game.
Set IsTrigger in the Collider component in Inspector.
Full Transcript
In Unity, 3D colliders are components that detect when objects touch or overlap. When two colliders meet, Unity checks if either is set as a trigger. If a collider's IsTrigger property is true, Unity calls OnTriggerEnter to handle the event. If IsTrigger is false, Unity calls OnCollisionEnter instead. This lets you decide if you want physical collisions or just trigger events. The example code shows how to print the name of the other object when these events happen. The execution table traces these events step by step, showing which function runs depending on the collider's trigger state. Understanding this helps you control game interactions clearly and avoid confusion about which event runs.