safer in-editor getworld without the polluting logs

This commit is contained in:
Mamadou Babaei
2024-08-16 18:00:54 +02:00
parent 85c7b769d1
commit fba4191f56
2 changed files with 18 additions and 12 deletions
@@ -539,17 +539,20 @@ UWorld* FSGXRTracker::FImpl::GetWorld()
}
/// NOTE
/// IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
/// "You are not on the main thread."
/// !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid
/// EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
/// The Editor is currently in a play mode.
// IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
// "You are not on the main thread."
// !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid
// EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
// The Editor is currently in a play mode.
if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld))
{
UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem<UUnrealEditorSubsystem>()};
if (IsValid(UnrealEditorSubsystem))
{
World = UnrealEditorSubsystem->GetEditorWorld();
/// NOTE
// This is exactly UnrealEditorSubsystem->GetEditorWorld() without all the annoying warnings that
// pollutes the logs. It's safe since we've already done all the checks.
World = GEditor->GetEditorWorldContext(false).World();
}
}
}