Unity cant find CollisionEvent

I’m trying to get particle collisions working so that if a rigid body gets hit by the particle it gets pushed backwards.

I thought I’d start simple and I tried to copy in the code from the scripting reference regarding OnParticleCollision - found here: Unity - Scripting API: MonoBehaviour.OnParticleCollision(GameObject)

However when I copy and paste the c# code into a new script attached to my particle system the compiler complains with the following error: “The nested type CollisionEvent' does not exist in the type UnityEngine.ParticleSystem’”. The bit it doesn’t like is the following line:

private ParticleSystem.CollisionEvent collisionEvents = new ParticleSystem.CollisionEvent[16];

It cant seem to find the CollisionEvent member of the ParticleSystem. All the online unity documentation seems to indicate that this is a member of ParticleSystem, but for some reason my version of unity does not accept this.

Anyone know what I’m doing wrong? It must be something pretty fundamental as I’m just trying to use the code from the website and it still doesn’t work.

Any help greatly appreciated.

I had the exact same problem when upgrading a project to Unity 5. I used “ParticleCollisionEvent” instead of “ParticleSystem.CollisionEvent” and then the code worked.

You should declare collisionEvents as:

private ParticleCollisionEvent[] collisionEvents = new ParticleCollisionEvent[16];

I tested “private ParticleSystem.CollisionEvent collisionEvents = new ParticleSystem.CollisionEvent[16];” on 4.5.4.
Did you copy everything of the c#-Code to your C#-script or only parts? I sometimes forget to write a curly bracket and the compiler shows me many warnings.