#  Any GameInstance Subclass Breaks Hot Reload

**URL:** <https://forums.unrealengine.com/t/any-gameinstance-subclass-breaks-hot-reload/662408>\
**Category:** C++\
**Tags:** unreal-engine, UE4-27, question, CPP\
**Created:** [October 4, 2022, 6:38pm UTC](https://forums.unrealengine.com/t/any-gameinstance-subclass-breaks-hot-reload/662408 "2022-10-04T18:38:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![catastrofur](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@catastrofur](https://forums.unrealengine.com/u/catastrofur)\
**Post date:** [October 4, 2022, 6:38pm UTC](https://forums.unrealengine.com/t/any-gameinstance-subclass-breaks-hot-reload/662408/1 "2022-10-04T18:38:29Z")

</div>

For the past several months, I’ve been getting periodic garbage collector crashes when using PIE. Recently, I found [Unreal Engine Issues and Bug Tracker (UE-140090)](https://issues.unrealengine.com/issue/UE-140090) and this is the exact issue I’ve been having. If you create a C++ subclass of UGameInstance and someone hot reloads twice in a row without running it, it cause this crash:

```auto
Fatal error: [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/Core/Private/Windows/WindowsPlatformMisc.cpp] [Line: 475] 
Pure virtual function being called

0x00007ff9961f474c KERNELBASE.dll!UnknownFunction []
0x00007ff90b190216 UE4Editor-Core.dll!ReportAssert() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsPlatformCrashContext.cpp:1644]
0x00007ff90b194218 UE4Editor-Core.dll!FWindowsErrorOutputDevice::Serialize() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsErrorOutputDevice.cpp:78]
0x00007ff90aeb242d UE4Editor-Core.dll!FOutputDevice::LogfImpl() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Misc\OutputDevice.cpp:61]
0x00007ff90b1ae6e0 UE4Editor-Core.dll!PureCallHandler() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsPlatformMisc.cpp:477]
0x00007ff98b406e44 VCRUNTIME140.dll!UnknownFunction []
0x00007ff90a456734 UE4Editor-CoreUObject.dll!UGCObjectReferencer::AddReferencedObjects() [D:\Build\++UE4\Sync\Engine\Source\Runtime\CoreUObject\Private\Misc\GCObjectReferencer.cpp:27]
0x00007ff90a5ad40f UE4Editor-CoreUObject.dll!TFastReferenceCollector<FGCReferenceProcessor<1>,FGCCollector<1>,FGCArrayPool,1>::ProcessObjectArray() [D:\Build\++UE4\Sync\Engine\Source\Runtime\CoreUObject\Public\UObject\FastReferenceCollector.h:881]
0x00007ff90a582fb5 UE4Editor-CoreUObject.dll!TFastReferenceCollector<FGCReferenceProcessor<1>,FGCCollector<1>,FGCArrayPool,1>::FCollectorTaskQueue::DoTask() [D:\Build\++UE4\Sync\Engine\Source\Runtime\CoreUObject\Public\UObject\FastReferenceCollector.h:403]
0x00007ff90a58be5d UE4Editor-CoreUObject.dll!TGraphTask<TFastReferenceCollector<FGCReferenceProcessor<1>,FGCCollector<1>,FGCArrayPool,1>::FCollectorTaskProcessorTask>::ExecuteTask() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Public\Async\TaskGraphInterfaces.h:886]
0x00007ff90ac11507 UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasks() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:1066]
0x00007ff90ac12860 UE4Editor-Core.dll!FTaskThreadAnyThread::ProcessTasksUntilQuit() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:889]
0x00007ff90ac19aa5 UE4Editor-Core.dll!FTaskThreadAnyThread::Run() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Async\TaskGraph.cpp:966]
0x00007ff90b1aff0b UE4Editor-Core.dll!FRunnableThreadWin::Run() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:86]
0x00007ff90b1a7050 UE4Editor-Core.dll!FRunnableThreadWin::GuardedRun() [D:\Build\++UE4\Sync\Engine\Source\Runtime\Core\Private\Windows\WindowsRunnableThread.cpp:35]
0x00007ff997a554e0 KERNEL32.DLL!UnknownFunction []
0x00007ff9986a485b ntdll.dll!UnknownFunction []

Crash in runnable thread TaskGraphThreadNP 2

```

I was able to reproduce this in a blank project with only the single C++ class in 4.27.2. Even when the this new class isn’t set as the default game instance, it still crashes because of default subobjects. I did some digging in PlayLevel.cpp, and it looks like game instances are only manually garbage collected at the end of the level in PIE:

```auto
// mark all objects contained within the PIE game instances to be deleted
for (TObjectIterator<UGameInstance> It; It; ++It)
{
	auto MarkObjectPendingKill = [](UObject* Object)
	{
		Object->MarkPendingKill();
	};
	ForEachObjectWithOuter(*It, MarkObjectPendingKill, true, RF_NoFlags, EInternalObjectFlags::PendingKill);
}

```

My question for the devs is this: should the game instances also be cleaned up after a hot reload? It’s really easy to accidentally hot reload twice, and it’s frustrating for my team to have persistent editor crashes. Any comment/work arounds from the devs would be much appreciated!
