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
@@ -129,17 +129,20 @@ UWorld* USGGloveTracker::FImpl::GetWorld()
} }
/// NOTE /// NOTE
/// IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting: // IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
/// "You are not on the main thread." // "You are not on the main thread."
/// !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid // !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid
/// EngineScriptHelpers::CheckIfInEditorAndPIE emitting: // EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
/// The Editor is currently in a play mode. // The Editor is currently in a play mode.
if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld)) if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld))
{ {
UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem<UUnrealEditorSubsystem>()}; UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem<UUnrealEditorSubsystem>()};
if (IsValid(UnrealEditorSubsystem)) 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();
} }
} }
} }
@@ -539,17 +539,20 @@ UWorld* FSGXRTracker::FImpl::GetWorld()
} }
/// NOTE /// NOTE
/// IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting: // IsInGameThread() check is to avoid EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
/// "You are not on the main thread." // "You are not on the main thread."
/// !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid // !(GEditor->PlayWorld || GIsPlayInEditorWorld) check is to avoid
/// EngineScriptHelpers::CheckIfInEditorAndPIE emitting: // EngineScriptHelpers::CheckIfInEditorAndPIE emitting:
/// The Editor is currently in a play mode. // The Editor is currently in a play mode.
if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld)) if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld))
{ {
UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem<UUnrealEditorSubsystem>()}; UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem<UUnrealEditorSubsystem>()};
if (IsValid(UnrealEditorSubsystem)) 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();
} }
} }
} }