Particle collision lets particles in a game hit objects or each other. This makes effects like sparks or smoke look real.
Particle collision in Unity
using UnityEngine; public class ParticleCollisionHandler : MonoBehaviour { private ParticleSystem particleSystem; void Start() { particleSystem = GetComponent<ParticleSystem>(); } void OnParticleCollision(GameObject other) { // Code to run when particles collide with 'other' Debug.Log($"Particle collided with {other.name}"); } }
The method OnParticleCollision is called automatically by Unity when particles hit another object.
You must have a ParticleSystem component on the same GameObject for this to work.
void OnParticleCollision(GameObject other)
{
Debug.Log($"Particle hit {other.name}");
}void OnParticleCollision(GameObject other)
{
if (other.CompareTag("Enemy"))
{
Debug.Log("Particle hit an enemy!");
}
}void OnParticleCollision(GameObject other)
{
// No collision if particle system is stopped
if (!particleSystem.isPlaying) return;
Debug.Log($"Particle collided with {other.name}");
}This script logs a message when the particle system starts and whenever a particle hits another object. Attach it to a GameObject with a ParticleSystem and enable collision in the ParticleSystem settings.
using UnityEngine; public class ParticleCollisionExample : MonoBehaviour { private ParticleSystem particleSystem; void Start() { particleSystem = GetComponent<ParticleSystem>(); Debug.Log("Particle system started."); } void OnParticleCollision(GameObject other) { Debug.Log($"Particle collided with {other.name}"); } }
Time complexity: Particle collision checks run every frame and depend on the number of particles and colliders.
Space complexity: Minimal extra memory is used for collision events.
Common mistake: Forgetting to enable 'Collision' in the ParticleSystem's settings, so OnParticleCollision never triggers.
Use particle collision when you want particles to interact with the environment. For simple visual effects without interaction, you can skip collision to save performance.
Particle collision lets particles detect and react when they hit objects.
Use OnParticleCollision(GameObject other) method to handle collisions.
Remember to enable collision in the ParticleSystem component for this to work.