Explosion particle effect lagging a game

hello guys, im using this explosion effect from playcanvas: Explosion Particle Effect | Learn PlayCanvas

In my game i have bomb explosions and this one fits well, however, i made a template out of this explosion so i can instantiate it on position of explosions, but whenever i instantiate and play particles explosion then the game lags very bad… i also tried to put it in hierarchy and playing in loop ingame but that just keeps lagging my game… does any of you had the same issue with this particle bomb effect? Or any ideas on how to reduce or better completely remove these lags from the game? But maaybe, if there was any other explosion effect that would be also great… thank you

Hi @smokys! I tried to remake your situation and it works without any lags. (I did see another problem when setting the position. To fix this, I disabled the template and enabled it by script after setting the correct position by script).

Thats really weird, it is lagging my game like quite a lot… all i need to do is just put the particle in hierarchy, set it to loop and the game instantly starts lagging…

How many explosions? Can you share your code or your project?

Hi @smokys,

Does it lag all the time or only when enabling the particles system?

The first it gets enabled it may lag once since it compiles a material/shader I think.

hello @Leonidas, firstly it lags more, but it keeps laging each time particles is enabled, i instantiate new explosion, enable it, and when its done explosing then it is removed… but each time it is spawned and enabled it lags

Maybe try instead of instantiating a new explosion, to reset/play from start the same particle effect?

I was also thinking about that one, but then i realized that there might be more than just one explosion at one time, there might be like 3 explosions, and it would look really weird if the explosion didnt even finished and was relocated to new position and started again and so on you know…:confused:

It even happens when one explosion occur… i unfortunatelly cannot share the link, but i can share a peek of the code

Yeah I understand. Most games to avoid the cost of constant allocations/deallocations of memory when spawning new objects they will create a pool instead.

So it’s time a particle system finishes, instead of destroying it you will send it back to the pool. And when requiring a new one, instead of instantiating it you will grab a disabled one fro mthe pool.

1 Like

If it happens continuously it may be a different bug.

But still, you will have to create a sample project that reproduces the issue otherwise it’s very hard to debug this.

Ok i reproduced it: Bombard 3D_COPY - PLAYCANVAS

First explosion make a bigger lags, after that there are not so hard, but still you can see it lags the game by watching the blue plane…

Hmm, apart from the first explosion all others are smooth.

Let’s see if anybody else can reproduce this.

Well they seem like they are smooth, because there are not much objects in game so u cant really see, but when you keep watching blue planes while dropping the bomb you can see the lags, or it looks a little like the camera was “shaking” - but its not, the shaking is turned off as it was part of the explosion…

E: Or try to hit the button as fast as you can…

I noticed that the screen shake is not working the first time I instantiate the explosion, but you don’t use this in your game. I suggest to disable one by one every part of the explosion to find out if there is a part that causes the lag.

1 Like

Well i actually tried that, even tried to change particle settings… nothing really worked until i disabled whole particle system

I avoided the first lag when enabling the particle system for the first time by setting all of my particle systems in front of the camera and on postInitialize disabling all them, I set the pre-warm to true, also I reuse these particle systems and don’t destroy them.