Bird
Raised Fist0
Unityframework~20 mins

Particle collision in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
Particle Collision Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this OnParticleCollision method?

Consider this Unity C# script snippet attached to a GameObject with a Particle System. What will be printed when a particle collides with another GameObject?

Unity
void OnParticleCollision(GameObject other) {
    Debug.Log($"Collided with: {other.name}");
}
AThe console prints: "Collided with: " followed by the name of the other GameObject.
BNothing is printed because OnParticleCollision is never called automatically.
CThe console prints "Particle collided" regardless of the other GameObject's name.
DA runtime error occurs because OnParticleCollision requires a ParticleSystem parameter.
Attempts:
2 left
💡 Hint

OnParticleCollision is a Unity event method triggered automatically when particles collide with other GameObjects.

🧠 Conceptual
intermediate
2:00remaining
Which component must be enabled for particle collisions to trigger OnParticleCollision?

In Unity, to detect particle collisions and trigger the OnParticleCollision method, which setting must be enabled on the Particle System?

ASet the Particle System's 'Play On Awake' to false.
BAdd a Rigidbody component to the Particle System GameObject.
CEnable the 'Collision' module in the Particle System and set 'Send Collision Messages' to true.
DEnable the 'Trigger' module in the Particle System.
Attempts:
2 left
💡 Hint

Look for the module that controls particle interactions with other objects.

🔧 Debug
advanced
2:00remaining
Why does this OnParticleCollision method never print anything?

Examine the following code attached to a GameObject with a Particle System. Despite particles colliding with other objects, nothing is printed in the console. What is the most likely cause?

Unity
void OnParticleCollision() {
    Debug.Log("Particle collided");
}
AThe Debug.Log statement is inside the wrong method; it should be in Update().
BThe Particle System's emission rate is set to zero.
CThe Particle System is missing a Collider component.
DThe method signature is incorrect; it must have a GameObject parameter to be called.
Attempts:
2 left
💡 Hint

Check the method signature required by Unity for particle collision callbacks.

📝 Syntax
advanced
2:00remaining
Which option correctly implements OnParticleCollision to count collisions?

You want to count how many particles collided with other objects. Which code correctly increments a collision count each time a particle collides?

Unity
int collisionCount = 0;

// Your OnParticleCollision method here
A
void OnParticleCollision(GameObject other) {
    collisionCount++;
}
B
void OnParticleCollision() {
    collisionCount++;
}
C
void OnParticleCollision(GameObject other) {
    collisionCount += other.GetInstanceID();
}
D
void OnParticleCollision(Collider other) {
    collisionCount++;
}
Attempts:
2 left
💡 Hint

Check the required method signature and parameter types for OnParticleCollision.

🚀 Application
expert
3:00remaining
How to detect which particles collided and get their positions?

You want to detect each individual particle that collided and get its position during the collision event. Which approach correctly achieves this in Unity?

AUse <code>ParticleSystem.EmitParams.position</code> inside OnParticleCollision to get collided particle positions.
BUse <code>ParticleSystem.GetCollisionEvents(GameObject, List&lt;ParticleCollisionEvent&gt;)</code> inside OnParticleCollision to get collision details including positions.
CUse <code>OnParticleCollision(GameObject other)</code> and access <code>other.transform.position</code> for particle positions.
DAdd a Collider to each particle and use OnCollisionEnter to get positions.
Attempts:
2 left
💡 Hint

Look for a ParticleSystem method that provides detailed collision event info.

Practice

(1/5)
1. What is the main purpose of the OnParticleCollision method in Unity's particle system?
easy
A. To stop the particle system from playing
B. To change the color of particles over time
C. To emit new particles continuously
D. To detect when particles collide with other objects

Solution

  1. Step 1: Understand the role of OnParticleCollision

    This method is a special Unity callback triggered when particles hit other objects in the scene.
  2. Step 2: Identify its main use

    It is used to detect collisions of particles, allowing you to respond to those events in code.
  3. Final Answer:

    To detect when particles collide with other objects -> Option D
  4. Quick Check:

    Particle collision detection = To detect when particles collide with other objects [OK]
Hint: Remember: OnParticleCollision detects particle hits [OK]
Common Mistakes:
  • Confusing particle emission with collision detection
  • Thinking it changes particle appearance
  • Assuming it stops the particle system
2. Which of the following is the correct signature for the OnParticleCollision method in a Unity C# script?
easy
A. void OnParticleCollision(GameObject other)
B. void OnParticleCollision(Collider other)
C. void OnParticleCollision(Particle other)
D. void OnParticleCollision()

Solution

  1. Step 1: Recall Unity's method signature

    The OnParticleCollision method receives a GameObject parameter representing the object hit by particles.
  2. Step 2: Match the correct parameter type

    Only void OnParticleCollision(GameObject other) uses GameObject as the parameter, which is correct.
  3. Final Answer:

    void OnParticleCollision(GameObject other) -> Option A
  4. Quick Check:

    Parameter type is GameObject = void OnParticleCollision(GameObject other) [OK]
Hint: OnParticleCollision always takes GameObject parameter [OK]
Common Mistakes:
  • Using Collider instead of GameObject
  • Omitting the parameter
  • Using Particle type which doesn't exist
3. Consider this Unity C# script attached to a GameObject with a Particle System:
void OnParticleCollision(GameObject other) {
    Debug.Log("Hit: " + other.name);
}
What will happen when particles collide with another object named "Wall"?
medium
A. The console will print: Hit: Wall
B. The particle system will stop emitting
C. Nothing will happen because OnParticleCollision is not called
D. An error will occur because other.name is invalid

Solution

  1. Step 1: Understand the method behavior

    When particles hit an object, OnParticleCollision is called with that object as other.
  2. Step 2: Analyze the Debug.Log statement

    The code prints "Hit: " plus the name of the collided object, which is "Wall".
  3. Final Answer:

    The console will print: Hit: Wall -> Option A
  4. Quick Check:

    Collision triggers log with object name = The console will print: Hit: Wall [OK]
Hint: OnParticleCollision logs object name on hit [OK]
Common Mistakes:
  • Assuming particle system stops on collision
  • Thinking method is never called
  • Believing other.name is invalid
4. Given this code snippet in a Unity script:
void OnParticleCollision(GameObject other) {
    int count = other.GetComponent<int>();
    Debug.Log(count);
}
What is the problem with this code?
medium
A. OnParticleCollision must return a value
B. GetComponent<int>() is invalid because int is not a component
C. The method should use Collider instead of GameObject
D. Debug.Log cannot print integers

Solution

  1. Step 1: Check GetComponent usage

    GetComponent<T> expects a Component type, but int is a primitive type, not a component.
  2. Step 2: Identify the error cause

    Using GetComponent<int>() causes a compile-time error because int is invalid here.
  3. Final Answer:

    GetComponent<int>() is invalid because int is not a component -> Option B
  4. Quick Check:

    GetComponent requires Component type = GetComponent<int>() is invalid because int is not a component [OK]
Hint: GetComponent needs a Component type, not primitives [OK]
Common Mistakes:
  • Thinking OnParticleCollision must return a value
  • Confusing parameter type with Collider
  • Believing Debug.Log can't print integers
5. You want to reduce the damage caused by particles when they collide with enemies, but only if the enemy's health is above 50. Which approach correctly uses OnParticleCollision to achieve this?
hard
A. Check the particle system's emission rate and reduce damage if emission is low.
B. Use OnParticleCollision() without parameters and reduce damage always.
C. In OnParticleCollision(GameObject other), get the enemy's health component, check if health > 50, then reduce damage accordingly.
D. Use OnParticleCollision(Collider other) and reduce damage without checking health.

Solution

  1. Step 1: Use correct method signature

    The method must be OnParticleCollision(GameObject other) to get the collided object.
  2. Step 2: Access enemy health and apply condition

    Retrieve the health component from other, check if health > 50, then reduce damage only in that case.
  3. Final Answer:

    In OnParticleCollision(GameObject other), get the enemy's health component, check if health > 50, then reduce damage accordingly. -> Option C
  4. Quick Check:

    Conditional damage based on health = In OnParticleCollision(GameObject other), get the enemy's health component, check if health > 50, then reduce damage accordingly. [OK]
Hint: Check enemy health inside OnParticleCollision before damage [OK]
Common Mistakes:
  • Using wrong method signature without parameters
  • Ignoring enemy health condition
  • Using Collider parameter instead of GameObject