I have a subclass of UGameInstanceSubsystem for managing background music in my game. It keeps a stack of audio components (allocated through UGameplayStatics::SpawnSound2D()) so I can have eg menu music take over from game music temporarily.
My front end UMG class plays some audio via this, plays nicely, and when I hit “Go!” it opens a new level (OpenLevelByName). But when that level loads, the current playing track becomes null in my subsystem, even though I’ve UPROPERTY’d the array. Even though game instance subsystems live outside of levels. Now I can put defensive guards around code to check for nulls, but it seems I’m missing something here. Why was that audio component GC’d?
There’s a (defaulted to false) flag you can specify when you call SpawnSound2D() “bPersistAcrossLevelTransitions” and setting that to true makes the crashes go away