From f61635c32741ee3e39e175b7cd5b9aff22a2219e Mon Sep 17 00:00:00 2001 From: mcgarrah <56135373+lumberyard-employee-dm@users.noreply.github.com> Date: Thu, 10 Jun 2021 14:59:09 -0500 Subject: [PATCH] Updated the SystemComponents in the Default Gem and Project Templates to initialize/deinitialize the Interface instance --- .../Code/Source/${Name}EditorSystemComponent.cpp | 16 ++++++++++++++++ .../Code/Source/${Name}EditorSystemComponent.h | 3 ++- .../Code/Source/${Name}SystemComponent.cpp | 16 ++++++++++++++++ .../Code/Source/${Name}SystemComponent.h | 3 +++ .../Code/Source/${Name}SystemComponent.cpp | 2 +- 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp index 4fca5e8d3c..fedc37da6b 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp +++ b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.cpp @@ -25,6 +25,22 @@ namespace ${SanitizedCppName} } } + ${SanitizedCppName}EditorSystemComponent::${SanitizedCppName}EditorSystemComponent() + { + if (${SanitizedCppName}Interface::Get() == nullptr) + { + ${SanitizedCppName}Interface::Register(this); + } + } + + ${SanitizedCppName}EditorSystemComponent::~${SanitizedCppName}EditorSystemComponent() + { + if (${SanitizedCppName}Interface::Get() == this) + { + ${SanitizedCppName}Interface::Unregister(this); + } + } + void ${SanitizedCppName}EditorSystemComponent::Activate() { AzToolsFramework::EditorEvents::Bus::Handler::BusConnect(); diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h index 296d2c3bcd..ef7b0a2f2e 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h +++ b/Templates/DefaultGem/Template/Code/Source/${Name}EditorSystemComponent.h @@ -29,7 +29,8 @@ namespace ${SanitizedCppName} AZ_COMPONENT(${SanitizedCppName}EditorSystemComponent, "${EditorSysCompClassId}"); static void Reflect(AZ::ReflectContext* context); - ${SanitizedCppName}EditorSystemComponent() = default; + ${SanitizedCppName}EditorSystemComponent(); + ~${SanitizedCppName}EditorSystemComponent(); private: static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp index 214d2cfe39..8f7eabf74e 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp +++ b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.cpp @@ -59,6 +59,22 @@ namespace ${SanitizedCppName} AZ_UNUSED(dependent); } + ${SanitizedCppName}SystemComponent::${SanitizedCppName}SystemComponent() + { + if (${SanitizedCppName}Interface::Get() == nullptr) + { + ${SanitizedCppName}Interface::Register(this); + } + } + + ${SanitizedCppName}SystemComponent::~${SanitizedCppName}SystemComponent() + { + if (${SanitizedCppName}Interface::Get() == this) + { + ${SanitizedCppName}Interface::Unregister(this); + } + } + void ${SanitizedCppName}SystemComponent::Init() { } diff --git a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h index 5eff2e6430..8e91650c65 100644 --- a/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h +++ b/Templates/DefaultGem/Template/Code/Source/${Name}SystemComponent.h @@ -35,6 +35,9 @@ namespace ${SanitizedCppName} static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); + ${SanitizedCppName}SystemComponent(); + ~${SanitizedCppName}SystemComponent(); + protected: //////////////////////////////////////////////////////////////////////// // ${SanitizedCppName}RequestBus interface implementation diff --git a/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp b/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp index 0d160bd45a..ed0a47d6db 100644 --- a/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp +++ b/Templates/DefaultProject/Template/Code/Source/${Name}SystemComponent.cpp @@ -66,7 +66,7 @@ namespace ${SanitizedCppName} ${SanitizedCppName}Interface::Register(this); } } - + ${SanitizedCppName}SystemComponent::~${SanitizedCppName}SystemComponent() { if (${SanitizedCppName}Interface::Get() == this)