From 0c71ab9ab8ddf078935bd836da1f76e37a4615d3 Mon Sep 17 00:00:00 2001 From: Mamadou Babaei Date: Fri, 7 Jun 2024 13:39:32 +0200 Subject: [PATCH] simplify getworld implementation --- .../Private/SGUtils/SGEngineUtils.cpp | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/Source/SenseGloveUtils/Private/SGUtils/SGEngineUtils.cpp b/Source/SenseGloveUtils/Private/SGUtils/SGEngineUtils.cpp index 88aecf0b..59f82e71 100644 --- a/Source/SenseGloveUtils/Private/SGUtils/SGEngineUtils.cpp +++ b/Source/SenseGloveUtils/Private/SGUtils/SGEngineUtils.cpp @@ -42,9 +42,6 @@ #include "Engine/GameViewportClient.h" #include "Engine/World.h" #include "Subsystems/EngineSubsystem.h" -#if WITH_EDITOR -#include "Subsystems/UnrealEditorSubsystem.h" -#endif /* WITH_EDITOR */ UWorld* FSGEngineUtils::GetWorld() { @@ -55,40 +52,19 @@ UWorld* FSGEngineUtils::GetWorld() { if (IsValid(GEditor)) { - const bool bIsPIE = GPlayInEditorID != -1; - if (!bIsPIE) { - const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(1)}; - if (WorldContext) - { - World = WorldContext->World(); - } - } - else - { - const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(GPlayInEditorID)}; + const bool bIsPIE = GPlayInEditorID != -1; + const int32 WorldPIEInstance = bIsPIE ? GPlayInEditorID : 1; + const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(WorldPIEInstance)}; if (WorldContext) { World = WorldContext->World(); } } - /// 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. if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld)) { - UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem()}; - if (IsValid(UnrealEditorSubsystem)) - { - /// 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(); - } + World = GEditor->GetEditorWorldContext(false).World(); } }