OnMouseDown not working on my Particle System
DISCLAIMER: this is my first ever Unity project (though I have programmed some before so I know a bit of lingo) and I'm mostly just playing around and learning. I am NOT necessarily looking for a perfect/best/optimized solution, I'm looking for a solution to my question as posed (if possible).
.
WHAT I HAVE: I'm building a board game where the board is planets around a sun, each with "orbit" rings around them and links between the rings (the orbits and links are what the player avatars "ride" on). The rings and links are all particle effects with a script containing an "OnMouseDown()" method.
.
THE GOAL: My player avatars to move between adjacent orbits (NOT tracks) when I click on those paths, including the particle effect rings and links.
.
MY PROBLEM: Everything I want to do works so far - clicked board objects move the player to them with no errors - except when I try to click on the Particle System orbits/links and nothing happens.
.
WHAT I'VE TRIED:
=> Debug.Log tags to see where/when I'm executing the code and how far I get within it. The code behaves flawlessly when clicking the planets and moons, but doesn't even activate and enter the method when I [try to] click on the orbit Particle Systems.
=> Adding the script to one of the linear Particle Systems whose transform.position is NOT inside another object: the script still didn't activate.
.
MY HYPOTHESES:
1) Maybe Particle Systems only click on an infinitesimal transform.position point(s) (of the system or even the individual particles???) and not the area/volume defined by either the Shape attribute or the [particle size + direction&duration of travel]. Possible solution: add a collider??? ( I'm not sure how to do that correctly IF it would even work at all)
2) Perhaps there's something about Particle Systems that precludes clicking on them altogether. Possible solution: replace the Particle Systems with images that can be clicked on?
.
THE HELP I'M SOLICITING: suggestions (with instructions) on ways I could change the area/volume, or the particles, of a Particle System so that an OnMouseDown method linked to it will trigger. Any help would be appreciated.
.
Answer by karl_jones · Jul 14, 2020 at 10:38 PM
OnMouseDown requires the object to have a collider and ParticleSystems dont have one by default. You can add a collider however you need to decide how accurate the collision detection needs to be. The simplest would be a box collider set to match the particle system bounds. You could update it every frame to match the exact size or just set it to a static value. If you want it so it only happens when you click on an actual particule then you will likely need a mesh collider. You can get a mesh version of the system by calling BakeMesh on ParticleSystemRenderer and then feeding that into a Mesh collider. It's going to hit your performance more than a simple box though. Try a box and see how that goes first. Just select the particle system gameObject and add a collider component.
Your answer
![](https://koobas.hobune.stream/wayback/20220613003205im_/https://answers.unity.com/themes/thub/images/avi.jpg)