- Home /
Make particle collide to only objects from one layer
Is that possible. I mean, if I have Player spaceShip on "Player" physical layer and enemies on "Enemy" physical level, and they shoot with particle systems, they do not frienly fire (I know about particle collisions with moving objects, but this thing works fine for me). I tried to set levels to objects that hav particle emitters attached, but looks like it dont works. (I set it like on a picture: https://www.dropbox.com/s/5hs3f8fm31yfynv/Screenshot%202014-10-07%2023.39.57.png?dl=0)
I also found "Collides With" setting on particle emitter collision settings, and it works fine, but is this possible to change its value from scripts, not inspector? Googling gives nothing for me :( https://www.dropbox.com/s/ok32slgjryr55th/Screenshot%202014-10-07%2023.38.53.png?dl=0
Answer by kir1251 · Oct 08, 2014 at 10:35 AM
Already found a way to do it, but still interested in easier version, if some.
//pSts is a gameObject with attached particle system
SerializedObject so = new SerializedObject(pSts.GetComponent<ParticleSystem>());
SerializedProperty it = so.GetIterator();
so.FindProperty("CollisionModule.collidesWith").intValue = 1 << LayerMask.NameToLayer("Enemy");//or "Player" for enemy particles
so.ApplyModifiedProperties();
UPD: this thing doesn't work outside Unity Editor :(
Your answer
![](https://koobas.hobune.stream/wayback/20220613164611im_/https://answers.unity.com/themes/thub/images/avi.jpg)