From c6628698200c5bd32e48dc6974f58bb4debee51b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 27 Nov 2018 20:56:02 +0000 Subject: [PATCH] Fixed duplicated registrations of ImGui Demo that were introduced in recent changes. --- Source/ImGui/Private/ImGuiModuleManager.cpp | 9 ++++++++- Source/ImGui/Private/ImGuiModuleManager.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/ImGui/Private/ImGuiModuleManager.cpp b/Source/ImGui/Private/ImGuiModuleManager.cpp index 7990dc2..a5a64e8 100644 --- a/Source/ImGui/Private/ImGuiModuleManager.cpp +++ b/Source/ImGui/Private/ImGuiModuleManager.cpp @@ -16,6 +16,9 @@ FImGuiModuleManager::FImGuiModuleManager() : ModuleCommands(*this) , ImGuiDemo(*this) { + // Register in context manager to get information whenever a new context proxy is created. + ContextManager.OnContextProxyCreated().AddRaw(this, &FImGuiModuleManager::OnContextProxyCreated); + // Typically we will use viewport created events to add widget to new game viewports. ViewportCreatedHandle = UGameViewportClient::OnViewportCreated().AddRaw(this, &FImGuiModuleManager::OnViewportCreated); @@ -169,7 +172,6 @@ void FImGuiModuleManager::AddWidgetToViewport(UGameViewportClient* GameViewport) // Make sure that we have a context for this viewport's world and get its index. int32 ContextIndex; auto& ContextProxy = ContextManager.GetWorldContextProxy(*GameViewport->GetWorld(), ContextIndex); - ContextProxy.OnDraw().AddLambda([this, ContextIndex]() { ImGuiDemo.DrawControls(ContextIndex); }); // Make sure that textures are loaded before the first Slate widget is created. LoadTextures(); @@ -208,3 +210,8 @@ void FImGuiModuleManager::AddWidgetsToActiveViewports() } } } + +void FImGuiModuleManager::OnContextProxyCreated(int32 ContextIndex, FImGuiContextProxy& ContextProxy) +{ + ContextProxy.OnDraw().AddLambda([this, ContextIndex]() { ImGuiDemo.DrawControls(ContextIndex); }); +} diff --git a/Source/ImGui/Private/ImGuiModuleManager.h b/Source/ImGui/Private/ImGuiModuleManager.h index fb420fd..4cd5077 100644 --- a/Source/ImGui/Private/ImGuiModuleManager.h +++ b/Source/ImGui/Private/ImGuiModuleManager.h @@ -59,6 +59,8 @@ private: void AddWidgetToViewport(UGameViewportClient* GameViewport); void AddWidgetsToActiveViewports(); + void OnContextProxyCreated(int32 ContextIndex, FImGuiContextProxy& ContextProxy); + // Event that we call after ImGui is updated. FSimpleMulticastDelegate PostImGuiUpdateEvent;