Crash when quitting the game using my game menu

Hi everyone, I’m having an error in the game when trying to quit using the Quit Game node from the BP, but the issue is caused by another C++ class that for some reason when I destroy it, it causes the editor to crash so I have posted the crash log:

MachineId:0F5BE70444CEECE9434A19A60344C455
EpicAccountId:

Fatal error: [File:D:\Build\++UE4+Release-4.14+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Obj.cpp] [Line: 755] 
BP_Subjects_C /Game/Levels/UEDPIE_0_Outside.Outside:PersistentLevel.BP_Subjects_2 failed to route BeginDestroy


UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:332]
UE4Editor_CoreUObject!UObject::ConditionalBeginDestroy() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\obj.cpp:755]
UE4Editor_CoreUObject!CollectGarbageInternal() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\garbagecollection.cpp:1298]
UE4Editor_CoreUObject!CollectGarbage() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\garbagecollection.cpp:1339]
UE4Editor_UnrealEd!UEditorEngine::EndPlayMap() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\playlevel.cpp:408]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1670]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:371]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2859]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launch.cpp:152]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

And here is the code that generates this error, it all happens on the Begin Destroy method that I have overridden, here is the code:

void ASubjects::BeginDestroy()
{
	Super::BeginDestroy();

	UKingdom::UnregisterSubject(this);
}

void UKingdom::UnregisterSubject(ASubjects* Subject)
{
	if (KingdomSubjects.Contains(Subject))
	{
		KingdomSubjects.Remove(Subject);
	}
}

Any help with this issue would be great. Thank you.

Hey WolfAlvein-

Please try unregistering the component before making the call to Super::BeginDestroy();. It’s likely that by the time it goes to unregister the actor, the reference has been lost and “this” is a null pointer. If he crash continues to occur, please provide the full code for your Subjects / Kingdom classes to help me reproduce the crash on my end.

Hi , you are right this has solved the issue and now I can quit the game from within it without any problem, Thank you.