From 8601401b680aaf36cddcbcadd867d27373c0b531 Mon Sep 17 00:00:00 2001 From: Colden Cullen Date: Wed, 8 May 2024 16:47:43 -0700 Subject: [PATCH] Better support PIE server processes This change defaults ImGui parent windows to the editor main window when there isn't a more specific one. --- Source/ImGui/Private/ImGuiModule.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/Source/ImGui/Private/ImGuiModule.cpp b/Source/ImGui/Private/ImGuiModule.cpp index ef80d08..22230f5 100644 --- a/Source/ImGui/Private/ImGuiModule.cpp +++ b/Source/ImGui/Private/ImGuiModule.cpp @@ -54,8 +54,15 @@ TSharedPtr FImGuiModule::FindOrCreateSessionContext(const int32 P Port += PIEInstance + 1; } +#if WITH_ENGINE + const FWorldContext* WorldContext = GEngine->GetWorldContextFromPIEInstance(PIEInstance); + UGameViewportClient* GameViewport = WorldContext ? WorldContext->GameViewport : GEngine->GameViewport; + if (IsValid(GameViewport)) + { + Context = CreateViewportContext(GameViewport); + } #if WITH_EDITOR - if (GIsEditor && PIEInstance == INDEX_NONE) + else if (GIsEditor) { const IMainFrameModule* MainFrameModule = FModuleManager::GetModulePtr("MainFrame"); const TSharedPtr MainFrameWindow = MainFrameModule ? MainFrameModule->GetParentWindow() : nullptr; @@ -64,21 +71,12 @@ TSharedPtr FImGuiModule::FindOrCreateSessionContext(const int32 P Context = CreateWindowContext(MainFrameWindow.ToSharedRef()); } } - else #endif - { -#if WITH_ENGINE - const FWorldContext* WorldContext = GEngine->GetWorldContextFromPIEInstance(PIEInstance); - UGameViewportClient* GameViewport = WorldContext ? WorldContext->GameViewport : GEngine->GameViewport; - if (IsValid(GameViewport)) - { - Context = CreateViewportContext(GameViewport); - } - else - { - Context = FImGuiContext::Create(); - } #endif + + if (!Context.IsValid()) + { + Context = FImGuiContext::Create(); } if (Context.IsValid())