Hello!
Sorry for reviving an old thread, but I’m having almost exactly the same issue discussed here. The only difference being that I will have a lot more than 3 particle emissions play during the same frame, so instantiating and positioning multiple particle systems would be quite laggy.
Most of my project is built with DOTS, but since particle systems aren’t DOTS-ified yet I still have to keep them as GameObjects (as far as I know).
Here’s my issue:
I’ve got a bunch of entities flying around shooting at each other (several thousands at once), and when they are killed I want them to explode. To do this, I’ve created an ExplosionSystem which runs on the main thread and has a reference to the particle system. The ExplosionSystem is invoked on a bunch of ExplosionEvents that are generated when entities are killed. My ExplosionEvent has two values: the position at which the explosion should occur and the size of the explosion.
So far I’ve got two ways of doing this:
protected override void OnEvent(ExplosionEvent explosion)
{
_particleSystem.transform.position = explosion.Position;
_particleSystem.Play();
}
The downside of this way being that it can not handle multiple ExplosionEvents per frame, with the upside being that it actually plays the explosion particle system correctly.
protected override void OnEvent(ExplosionEvent explosion)
{
var emitParams = new ParticleSystem.EmitParams
{
position = explosion.Position,
startSize = explosion.Size,
startLifetime = explosion.Size / 5f,
};
_particleSystem.Emit(emitParams, 100);
}
The upside of doing it this way being that it can handle multiple ExplosionEvents per frame, but with the downside that the particle system is not being run properly.
What do I mean by it “not being run properly”? Well, from just looking at the particles generated I can see that something is wrong with the .Emit-way of doing it, because while .Play generates a bunch of different particles with different rotations, velocities and sizes, .Emit seems to either generate 100 exactly identical particles, or only one single particle, because that’s the way it looks. (I’ll add GIFs of both versions if anyone wants clarification of what I mean.)
If any of you know of a way to either 1. make the .Emit-particles behave like normal .Play-particles, or 2. allow .Play to be executed multiple times per frame at different positions, then I’d appreciate some guidance!
Note: I’m aware that this could also be done by having a pool of explosion particle system GameObjects that the ExplosionSystem pulls from, which would allow me to run .Play on each particle system from the pool. The reason why I’d rather use a different solution is because I feel like this solution is a bit overengineered, when it feels like I’ve (hopefully) just missed a parameter somewhere when calling .Emit. If the pool is the best solution though, please do let me know!