I have this error when stopping the game in the editor:
Assertion failed: false [File:D:\build++UE5\Sync\Engine\Source\Editor\UnrealEd\Private\PlayLevel.cpp] [Line: 517] Object ‘World /Game/Game/Maps/GamePlay/Arena01/UEDPIE_0_L_Arena01.L_Arena01’ from PIE level still referenced. Shortest path from root: (Garbage) (async) NavigationPath /Game/Game/Maps/GamePlay/Arena01/UEDPIE_0_L_Arena01.L_Arena01:NavigationSystemV1_0.NavigationPath_3674 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^ This reference is preventing the old World from being GC’d ^ → UObject* UObject::Outer = (Garbage) NavigationSystemV1 /Game/Game/Maps/GamePlay/Arena01/UEDPIE_0_L_Arena01.L_Arena01:NavigationSystemV1_0 → UObject* UObject::Outer = (Garbage) World /Game/Game/Maps/GamePlay/Arena01/UEDPIE_0_L_Arena01.L_Arena01
I know it’s caused because I’m using a world reference inside a thread.
I don’t know if this is the best solution but if the GC waits just one second the thread will finish execution and release the reference.
Although if there is a better way to handle this problem I would like to be let me know please.
This is my first time using threads in Unreal… any help is welcome.
//This is used as if it was a PostPIEEnded event
EndPlayDelegateHandle = FGameDelegates::Get().GetEndPlayMapDelegate().AddUObject(this, &AEnemyAIController::OnMapChange, (uint32)0);
void AEnemyAIController::OnMapChange(uint32 MapChangeFlags)
{
if (Runnable!=nullptr)
{
Runnable->Stop();
Runnable->Kill();
}
}
But the garbage collector is faster… That is to say, it does not work.
An event or delegate that can be overwritten before the world is destroyed, does anyone know?
I found that if I unmark the navigation system as garbage at the end of the task that executes the thread, the game does not crash and everything works perfectly.
void Task()
{
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(Controller->GetWorld());
if (!IsValid(NavSys)) return;
// Some code here
NavSys->ClearGarbage();
}
The question now is… should I delete the “NavSys” pointer manually?
And how would it be done correctly?
I suspect that freeing memory C++ style is not the right way to do it…
delete NavSys:
And style C neither, right?
free(NavSysy)
If someone can resolve this doubt for me, I think the job is done.
Anyway, I would like to know how to do it manually… I think it has not to be very complicated… the difficult thing is finding the information on how to do it.