simplify getworld implementation
This commit is contained in:
@@ -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()
|
||||
{
|
||||
@@ -54,43 +51,22 @@ UWorld* FSGEngineUtils::GetWorld()
|
||||
if (GIsEditor)
|
||||
{
|
||||
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 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<UUnrealEditorSubsystem>()};
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsValid(World) && IsValid(GEngine))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user