Garbage collection and Blueprint questions

Hi, I have a game mostly done in BP but with a bit of C++. I noticed that every 60 seconds a small lag or screen freeze (of about 0.25 seconds) was spoiling the gameplay a bit, so I asked about it and was told that every 60 seconds pointers are cleared, and as I said I had many actors spawning and being destroyed (about 300 or 400 per minute, maybe) I was recommended to recycle those actors instead of destroying them.

That’s what I’ve done, recycle all of them. And the screen freeze is still there! I’m experimenting with stuff to try to find out the cause, if anyone has suggestions I would thankfully read them.

Other than that, I have a couple of questions. For issues with garbage collection I’ve seen in my searches that there’s a function called ForceGarbageCollection. Does that the exact same effect as the one from BP-exposed Collect Garbage function? I say this because I’ve tried that function and seems not to be forcing garbage collestion, I’ve tried calling it every Tick in the level blueprint, which should be killing performance, but is not affecting it nor is stopping the screen freeze.

Any suggestions? I’m very interested in knowing ways to control when to perform garbage collection so it does not badly affect gameplay experience each 60 seconds.

Actually I had overlooked a part of the BP and the Collect Garbage function wasn’t executing. Using it in Tick kills performance, as expected.

My solution has been calling Collect Garbage each time the character dies (when it won’t spoil gameplay), and now it seems that the garbage collection performed by the engine each 60 seconds isn’t noticeable, so it seems it’s solved!

Furthermore, just for curiosity I wanted to check out in a backup of the project how would it be to use that Collect Garbage function when I was destroying about 300-400 actors per minute, if it would solve the screen freeze as well: and it does!

Here are the differences I’ve observed: in the project backup where I recycle all the spawned actors, the first garbage collection (at 60 seconds from start) is the only one that is noticeable, as well as sometimes the one called when the character dies (in the cases when he has survived a long time so more time since last garbage collection has elapsed).

In the older backup with no recycling and 300-400 actor destroys per minute, the only noticeable garbage collections are the first 60 seconds one and the one called for the first death. No any others, so hilariously this backup without the recycling is showing better performance with less screen freeze!

So now I’m staying with the older backup, because gives less screen freeze (and any other downsides), in fact the only screen freeze I would still wish to avoid here is the one of the first 60 seconds, since the one of the first death doesn’t affect gameplay since character is dying and things are restarting.

So do you know a way to force the first 60 seconds garbage collection be performed at a set moment (the first time in which character dies, which is usually often before 60 seconds have elapsed)? All the next garbage collections aren’t noticiable thanks to calling Garbage Collect each time character dies, but the first is still noticeable, even when character dies before it happens.

I replied in your other post, but also am leaving this here for good measure.
AiMoveTo bad.

Replied you there.