simplify getworld implementation
This commit is contained in:
@@ -42,9 +42,6 @@
|
|||||||
#include "Engine/GameViewportClient.h"
|
#include "Engine/GameViewportClient.h"
|
||||||
#include "Engine/World.h"
|
#include "Engine/World.h"
|
||||||
#include "Subsystems/EngineSubsystem.h"
|
#include "Subsystems/EngineSubsystem.h"
|
||||||
#if WITH_EDITOR
|
|
||||||
#include "Subsystems/UnrealEditorSubsystem.h"
|
|
||||||
#endif /* WITH_EDITOR */
|
|
||||||
|
|
||||||
UWorld* FSGEngineUtils::GetWorld()
|
UWorld* FSGEngineUtils::GetWorld()
|
||||||
{
|
{
|
||||||
@@ -55,40 +52,19 @@ UWorld* FSGEngineUtils::GetWorld()
|
|||||||
{
|
{
|
||||||
if (IsValid(GEditor))
|
if (IsValid(GEditor))
|
||||||
{
|
{
|
||||||
const bool bIsPIE = GPlayInEditorID != -1;
|
|
||||||
if (!bIsPIE)
|
|
||||||
{
|
{
|
||||||
const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(1)};
|
const bool bIsPIE = GPlayInEditorID != -1;
|
||||||
if (WorldContext)
|
const int32 WorldPIEInstance = bIsPIE ? GPlayInEditorID : 1;
|
||||||
{
|
const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(WorldPIEInstance)};
|
||||||
World = WorldContext->World();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const FWorldContext* WorldContext{GEditor->GetPIEWorldContext(GPlayInEditorID)};
|
|
||||||
if (WorldContext)
|
if (WorldContext)
|
||||||
{
|
{
|
||||||
World = WorldContext->World();
|
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))
|
if (!IsValid(World) && IsInGameThread() && !(GEditor->PlayWorld || GIsPlayInEditorWorld))
|
||||||
{
|
{
|
||||||
UUnrealEditorSubsystem* UnrealEditorSubsystem{GEditor->GetEditorSubsystem<UUnrealEditorSubsystem>()};
|
World = GEditor->GetEditorWorldContext(false).World();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user