Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Trigger vs Collision Detection in Unity
📖 Scenario: You are creating a simple Unity scene where a player cube moves and interacts with objects. You want to learn the difference between triggers and collisions by setting up two cubes: one that detects collisions and one that detects triggers.
🎯 Goal: Build a Unity script that detects when the player cube collides with a solid cube and when it enters a trigger cube. You will set up the data, configure the colliders, write the detection logic, and complete the script to show messages in the Unity Console.
📋 What You'll Learn
Create a player GameObject with a Rigidbody and BoxCollider
Create two cubes: one with a BoxCollider (collision) and one with a BoxCollider set as trigger
Write a C# script with OnCollisionEnter and OnTriggerEnter methods
Print distinct messages to the Console for collision and trigger events
💡 Why This Matters
🌍 Real World
Games and interactive apps often need to detect when objects touch or overlap. Understanding triggers and collisions helps create realistic and responsive behaviors.
💼 Career
Game developers and interactive media programmers use collision and trigger detection daily to build gameplay mechanics and user interactions.
Progress0 / 4 steps
1
Setup Player and Cubes
Create a GameObject called player with a Rigidbody and a BoxCollider. Also create two cubes named solidCube and triggerCube with BoxCollider components. Do not set any collider as trigger yet.
Unity
Hint
Use new GameObject("player") to create the player and add components with AddComponent<T>(). Use CreatePrimitive(PrimitiveType.Cube) for the cubes.
2
Configure Trigger Collider
Set the BoxCollider on triggerCube to be a trigger by setting its isTrigger property to true.
Unity
Hint
Use GetComponent<BoxCollider>() on triggerCube and set isTrigger = true.
3
Write Collision and Trigger Detection Methods
Create a C# script called PlayerCollisionDetector with OnCollisionEnter(Collision collision) and OnTriggerEnter(Collider other) methods. In OnCollisionEnter, print "Collision with solidCube detected" if the collided object is solidCube. In OnTriggerEnter, print "Trigger entered with triggerCube" if the other collider is triggerCube.
Unity
Hint
Use OnCollisionEnter(Collision collision) and OnTriggerEnter(Collider other) methods. Check the gameObject.name to identify the cubes and use Debug.Log() to print messages.
4
Attach Script and Finalize Setup
Attach the PlayerCollisionDetector script to the player GameObject. Position the solidCube and triggerCube near the player so that moving the player will cause collision and trigger events.
Unity
Hint
Use AddComponent<PlayerCollisionDetector>() on player. Set positions of solidCube and triggerCube so they are near the player.
Practice
(1/5)
1. What is the main difference between a trigger and a collision in Unity?
easy
A. Triggers detect overlaps without blocking movement, collisions detect physical contact and block movement.
B. Triggers block movement, collisions only detect overlaps.
C. Triggers require Rigidbody, collisions do not.
D. Triggers and collisions behave exactly the same.
Solution
Step 1: Understand trigger behavior
Triggers detect when objects overlap but do not physically block each other.
Step 2: Understand collision behavior
Collisions detect physical contact and prevent objects from passing through each other.
Final Answer:
Triggers detect overlaps without blocking movement, collisions detect physical contact and block movement. -> Option A
Quick Check:
Trigger = overlap, Collision = block [OK]
Hint: Triggers overlap only; collisions block movement [OK]
Common Mistakes:
Confusing triggers with collisions as both blocking movement
Thinking triggers require Rigidbody always
Assuming collisions do not block movement
2. Which of the following is the correct way to make a collider act as a trigger in Unity?
easy
A. Add a Rigidbody component only.
B. Disable the collider component.
C. Set the collider's Is Trigger property to true.
D. Set the collider's material to None.
Solution
Step 1: Identify trigger setup
In Unity, to make a collider a trigger, you must enable its Is Trigger checkbox.
Step 2: Verify other options
Adding Rigidbody or disabling collider does not make it a trigger; setting material to None affects physics but not trigger behavior.
Final Answer:
Set the collider's Is Trigger property to true. -> Option C
Quick Check:
Is Trigger = true for triggers [OK]
Hint: Enable Is Trigger checkbox on collider [OK]
Common Mistakes:
Adding Rigidbody alone to make trigger
Disabling collider thinking it triggers events
Changing material instead of Is Trigger
3. Consider this Unity C# code snippet:
void OnTriggerEnter(Collider other) {
Debug.Log("Triggered by " + other.name);
}
void OnCollisionEnter(Collision collision) {
Debug.Log("Collided with " + collision.gameObject.name);
}
What will be printed if an object with a collider marked as trigger overlaps another object with a collider and Rigidbody?
medium
A. No message will print.
B. Only "Collided with [object name]" will print.
C. Both messages will print.
D. Only "Triggered by [object name]" will print.
Solution
Step 1: Analyze trigger event
When a collider marked as trigger overlaps another collider with Rigidbody, OnTriggerEnter is called.
Step 2: Analyze collision event
OnCollisionEnter is called only when colliders physically collide (not triggers).
Final Answer:
Only "Triggered by [object name]" will print. -> Option D
Quick Check:
Trigger collider calls OnTriggerEnter only [OK]
Hint: Trigger collider calls OnTriggerEnter, not OnCollisionEnter [OK]
Common Mistakes:
Expecting both trigger and collision messages
Thinking OnCollisionEnter triggers on overlap
Confusing collider types for events
4. You wrote this code but OnTriggerEnter is never called:
B. The collider's Is Trigger property is not enabled.
C. The method name is misspelled.
D. The object has no Rigidbody component.
Solution
Step 1: Check trigger setup
OnTriggerEnter only fires if the collider has Is Trigger enabled.
Step 2: Verify other conditions
Rigidbody is needed on one object but missing Rigidbody alone won't prevent OnTriggerEnter if Is Trigger is off; method name is correct; collider disabled would prevent all events.
Final Answer:
The collider's Is Trigger property is not enabled. -> Option B
Quick Check:
Is Trigger must be true for OnTriggerEnter [OK]
Hint: Enable Is Trigger to get OnTriggerEnter calls [OK]
Common Mistakes:
Forgetting to enable Is Trigger
Assuming Rigidbody absence blocks trigger
Misspelling method name
Not enabling collider component
5. You want to detect when a player enters a zone without blocking their movement, but also detect when the player physically hits a wall. How should you set up the colliders and Rigidbody components?
hard
A. Set the zone collider as trigger (Is Trigger = true), the wall collider as non-trigger, and add Rigidbody to the player.
B. Set both zone and wall colliders as triggers, add Rigidbody to the player.
C. Set the zone collider as non-trigger, wall collider as trigger, and add Rigidbody to the player.
D. Remove Rigidbody from player and set all colliders as non-trigger.
Solution
Step 1: Configure zone for overlap detection
Set the zone collider's Is Trigger to true so it detects player entering without blocking movement.
Step 2: Configure wall for physical collision
Set the wall collider as non-trigger to physically block the player.
Step 3: Rigidbody requirement
Add Rigidbody to the player so physics and trigger events work properly.
Final Answer:
Set the zone collider as trigger (Is Trigger = true), the wall collider as non-trigger, and add Rigidbody to the player. -> Option A
Quick Check:
Trigger zone + Rigidbody player + solid wall = correct setup [OK]
Hint: Trigger zone collider, solid wall collider, Rigidbody on player [OK]
Common Mistakes:
Making wall a trigger so player passes through
Not adding Rigidbody to player
Setting zone collider as non-trigger blocking player