From a8ba10d07417816967bf6174e782ee0d6beac6c0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 25 Nov 2018 21:26:06 +0000 Subject: [PATCH] Added code that moves module properties to hot-reloaded modules. --- Source/ImGui/Private/ImGuiModule.cpp | 19 ++++++++++++++++++- Source/ImGui/Public/ImGuiModule.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/ImGui/Private/ImGuiModule.cpp b/Source/ImGui/Private/ImGuiModule.cpp index 63bb1ab..c1cba99 100644 --- a/Source/ImGui/Private/ImGuiModule.cpp +++ b/Source/ImGui/Private/ImGuiModule.cpp @@ -130,6 +130,12 @@ void FImGuiModule::StartupModule() void FImGuiModule::ShutdownModule() { + // In editor store data that we want to move to hot-reloaded module. + +#if WITH_EDITOR + TOptional PropertiesToMove = ImGuiModuleManager->GetProperties(); +#endif + // Before we shutdown we need to delete managers that will do all the necessary cleanup. #if WITH_EDITOR @@ -147,7 +153,7 @@ void FImGuiModule::ShutdownModule() // deleted. This can cause troubles after hot-reload when code in other modules calls ImGui interface functions // which are statically bound to the obsolete module. To keep ImGui code functional we can redirect context handle // to point to the new module. - FModuleManager::Get().OnModulesChanged().AddLambda([this](FName Name, EModuleChangeReason Reason) + FModuleManager::Get().OnModulesChanged().AddLambda([this, PropertiesToMove] (FName Name, EModuleChangeReason Reason) mutable { if (Reason == EModuleChangeReason::ModuleLoaded && Name == "ImGui") { @@ -155,6 +161,12 @@ void FImGuiModule::ShutdownModule() if (&LoadedModule != this) { ImGuiImplementation::SetImGuiContextHandle(LoadedModule.GetImGuiContextHandle()); + + if (PropertiesToMove.IsSet()) + { + LoadedModule.SetProperties(PropertiesToMove.GetValue()); + PropertiesToMove.Reset(); + } } } }); @@ -162,6 +174,11 @@ void FImGuiModule::ShutdownModule() } #if WITH_EDITOR +void FImGuiModule::SetProperties(const FImGuiModuleProperties& Properties) +{ + ImGuiModuleManager->GetProperties() = Properties; +} + ImGuiContext** FImGuiModule::GetImGuiContextHandle() { return ImGuiImplementation::GetImGuiContextHandle(); diff --git a/Source/ImGui/Public/ImGuiModule.h b/Source/ImGui/Public/ImGuiModule.h index 1a261ca..10b8adb 100644 --- a/Source/ImGui/Public/ImGuiModule.h +++ b/Source/ImGui/Public/ImGuiModule.h @@ -148,6 +148,7 @@ public: private: #if WITH_EDITOR + virtual void SetProperties(const class FImGuiModuleProperties& Properties); virtual struct ImGuiContext** GetImGuiContextHandle(); #endif };