I’m getting an hard time figuring out how to reuse ParticleSystems. Whenever I try to reuse a previous ParticleSystem (which I deactived after a given T) it simply doesn’t emit any particles anymore. The ParticleSystem is non-looping, doesn’t have playOnAwake set and under the emission pane I only have a single burst at time == 0.
When I want to reuse a particle system I do the following:
Which should remove any leftover particles, set simulation time to zero and then start the ParticleSystem playback again, but it simply doesn’t show anything at all.
what i do is just set the game object the root particle system is on as false for SetActive (to pool it). when i drain an instance from the pool i SetActive(true), and run the following:
So, the pooling system had a little flaw but that wasn’t the problem. The ps is still not reset. May it depend on the fact that after grabbing it from the pool I also change its parent? Maybe that messes up the particle rendering process somehow.
Whenever the GameObject is re-activated Unity somehow resets it and the ps is correctly played. Fortunately this behaviour is ok for my use case but it would be helpful knowing how to correctly reset a ps without relying on playOnAwake.
For me calling Stop() fully resets (and clears) the particle system if i remember correctly. Then calling Play() afterwards results in the same behavior as playOnAwake. I wouldn’t suggest using playOnAwake if you are currently. I would suggest the system you are making for particle pooling instead uses Play manually. You also probably want to register things to the pool right after instantiate instead of only when retiring them, then using OnDestroy to actually drain the instance out of the pool.
The only thing about the transform change that should be worrying is that if the parent you change to gets destroyed, the system will as well (which is relevant to pooling, which you probably dont want to do)
For some reason using Stop and Play wasn’t working for me. I’m using a generic pooler (in the sense that it is not dedicated to particle systems) that maintains collections of many different GameObject types. For that reason any init tasks are performed either OnEnable in appropriate scripts or immediately after taking an instance from the pool (in the code consuming the instance, so to speak). Using playOnAwake will correctly reset the ps before playing it again when the GameObject is activated. I guess Unity knows how its own ParticleSystem class works.
Another (strange?) issue is the fact that ParticleSystem.IsAlive() always returns true even if I only have a single burst with particles having 1 sec lifetime. Maybe the two errors are related but I really couldn’t spend too much time investigating the matter once I was sure it was working.