Particle sytems killed when calling Collect Garbage function

Hi, I am forcing garbage collection through Collect Garbage function in level Blueprint each time character dies and stuff is reseted. When that happens some particle systems are destroyed.

I understand why some of them, the particle systems spawned by already destroyed actors, are destroyed, and it’s because their spawners had been destroyed and garbage collection is cleaning their pointers and references.

But the fact is that it’s also killing emitters spawned in the level Blueprint, which I would like to avoid. Is there a way to prevent garbage collection from killing level blueprint-spawned particle systems?

Hi Albert,

I attempted to reproduce what you are seeing but so far I haven’t been able to. This is what I am doing:

  • Set the Level Blueprint to spawn particles On Begin Play and more particles if I press a key.
  • Set Collect Garbage on a button press as well.
  • I then created a blueprint that would destroy a mesh on a delay and spawn a particle emitter.
  • After the meshes are destroyed, I Collect Garbage and no ‘Level Blueprint created’ emitters are affected.

Can you try to reproduce your issue in a new project and if you can, post the repro steps?

Hi TJ, thanks for your attention. There are some differences between our cases.

In the case affecting particle systems spawned in the BP of destroyed actors in which the emitters are destroyed by Collect Garbage, the particles are spawned some time before the spawner actor is destroyed, and not after manually destroying the actor in BP as in the last picture you show. So that’s, I guess, why in your case particles aren’t destroyed, but I have no problem with thissituation (in which the particles are spawned from an actor than gets later destroyed and then pointer-cleaned by Collect Garbage).

In the more important case, the one affecting particle systems spawned in the Level Blueprint, the situation in which I see them destroyed by Collect Garbage is when they are spawned just before calling Collect Garbage, so like this:
Tick Event → some filtering → Spawn Emitter At Location → Collect Garbage

Do you know how to avoid in that case the destroying of the particle? It also happens if I spawn the particle immediately after (Collect Garbage → Spawn Emitter At Location) and if I do it after a Delay of World Delta Seconds, but not if the Delay is for example 2 * World Delta Seconds.

I’m going to continue to look into this further, but what is your reason for wanting to collect garbage this often? The engine automatically collects garbage in the background and the Collect Garbage node is only meant to be used periodically when frame rate hitches can be spared.

I’m using Collect Garbage every time the character dies and some stuff in level is reseted, because is the ocasion when the gameplay can’t be affected by it; the normal garbage collection performed by the engine every 60 seconds causes a screen freeze of about 0.25 seconds in my game if I don’t use more often than that, so that’s why I call it in the mentioned occassions. I said in Tick, but also that with some filtering so it’s only called when character dies.

I was told it could be caused by destroying a lot of actors each minute as garbage collection would have to clear a huge number of pointers, so I completely rebuilt the system I used for spawning hazards in the level so everything was recycled and not destroyed. But the screen freeze was still there.

Then I found Collect Garbage function, which used in the mentioned circumstances prevents garbage collection from freezing the game in normal gameplay situations (calling it when character dies prevents that each 60 seconds there’s a small freeze).

Hey Albert -

Does it make a difference if you save a reference to the Particle System that you spawn? Easiest way to do that is to right click on the return value of the Spawn Emitter node, and select “Promote to Variable”

Hi Albert,

We haven’t heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you still have questions about this, please respond to Nick’s post above.

Thanks, TJ