My onParticleCollision() isn't working

I have been looking all over the internet for an answer. However, none of them seems to be a solution for me.

I am trying to get particle collision on an enemy for this game I am working one. The particle system acts like cold mist and when the enemy runs into the particles, they are to slow down. However, onParticleCollision() isn’t even being activated.

Here is my snippet.

private void OnParticleCollision(GameObject other)
    {
        Debug.Log("Particle collided");
        Debug.Log(other.tag);
        if (other.tag == "ColdAir")
        {
            chilly = true;
        }
    }

I also got some screenshots of the properties of the inspector menu.

Now, why isn’t it being activated correctly? I have wasted a good 3 hours trying to figure this out.

8952663--1229226--Screenshot 2023-04-16 123414.png

Your collider has “IsTrigger” enabled. Triggers don’t generate collisions, by definition: their only purpose is to trigger actions when objects go inside them.

Either use OnParticleTrigger if you want to use triggers, or uncheck “IsTrigger” otherwise.

Also, you’re using a 3D physics collider and have selected the world type as 2D.

1 Like

That was temporarily until I figured out how to rotate it as I need it facing a specific direction.

It works now. thx. Although I swear I tried that before with same results. However, with the World 3D set, it doesn’t work with me. For some odd reason I can’t set the direction, which makes it out of control.

if your “cold mist” should slow particles down, perhaps use a particle system force field instead and apply drag when inside.

That, I wouldn’t know how to do yet. Still quite new at particle systems.

something like:

  • enable external forces module,
  • create new game object that contains a ParticleSystemForceField component,
  • add force field to external forces list,
  • tweak shape/size/drag in the force field, whilst particles are travelling though it

Thanks. That helped a lot. So thanks again.

1 Like

Hi, I’m actually also having trouble getting OnParticleCollision callback.
My physics world and particle system world mode is both 2D, my colliders aren’t marked as isTrigger. It also detects collisions - i.e, moves the particles accordingly when a collider touches them, but the actual OnParticleCollision isn’t called.

I’ve tried both when the script with the OnParticleCollision methoed sits on the game obejct that has a collider, and when it’s on the particle system. In no case do I get the code inside OnParticleCollision to execute (currently just a debug statement). Any help with this?

EDIT

Well I’ll be happy to help you, me.

In order for this to actually work, aside from what’s been said you need to also:

  1. Mark “Send Collision Messages” as true (on the collision tab inside the particle system).
  2. Make sure either your collider-object has a kinematic Rigidbody, or you particle system has “Allow dynamic collisions” set (I think that’s what its called). If it deosn’t work than it’s some other combos, but that’s the gist of it.
    Oh and I got it to work when OnParticleCollision was on a script that sits on the colliding object, and not on the PS.

It would have been better to allow OnParticleTrigger that passed the collider as reference, so the triggered collider could execute code, without causing displacement in the particles, but oh well.

Check “Send Collision Messages” in the collision module inspector.

1 Like

Hello, is it possible to use OnParticleCollision (with “Send Collision Messages” on) and still have the particles go through the object (object’s collider is trigger !) ?
I want particles to damage the player but not physically interact with it, they should just continue their movement.
Is this possible?

1 Like

Adding to my previous post (just above) : Is there a third party 2D particle system asset ?
The particle system in Unity is 3D and some particles are behind the 2D objects.
I want my particles to be on the same Z (Or same layer order)

Edit: I found the Layer Order in the Rendering part of the Particle System, so that’s ok now.

But are there good alternatives for the Unity Particle system, like some 3rd party asset?

Yes, use the Trigger Module instead of the Collision Module.

1 Like