Garbage Collection causing lag on level unload

Hi, I’m making a game akin to Limbo/Inside where the level loading/unloading is meant to be seamless (eg: no load screens) I’m having an issue where GarbageCollection is causing sharp lag spikes whenever I unload a level.

I have tested loading/unloading via two methods in a packaged development build:

  1. Level Streaming : Using ‘Load Stream (by Name)’ to load / ‘Unload Stream Level (by Name)’ to unload with a persistent level housing sublevels that are set initially unloaded.

  2. Level Instancing : Using ‘Load Level Instance (by Name)’ to load / ‘Set is Requesting Unload and Removal’ with a persistent level with no sublevels in editor.

Both give me similar results, which look like this (which unsurprisingly creates a very distracting lag spike in-game):

My GC settings are:

Any tips on diagnosing this greatly appreciated!

UPDATE : A default setting setting forces GC after streaming a level out, which caused my CG spike:

s.ForceGCAfterLevelStreamedOut

Turning this off appears to have resolved the issue.

Solution credit goes to : Petr Leontev
(Level Streaming And Garbage Collection Optimization Tweaks In Unreal Engine 4)

1 Like