diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.cpp b/Code/Tools/ProjectManager/Source/PythonBindings.cpp index 0672e02ff4..90e18f5f27 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.cpp +++ b/Code/Tools/ProjectManager/Source/PythonBindings.cpp @@ -286,29 +286,8 @@ namespace O3DE::ProjectManager m_registration = pybind11::module::import("cmake.Tools.registration"); m_engineTemplate = pybind11::module::import("cmake.Tools.engine_template"); - // register the current engine if it isn't already - bool registerThis = true; - auto allEngines = m_registration.attr("get_engines")(); - if (pybind11::isinstance(allEngines)) - { - for (const auto& engine : allEngines) - { - AZ::IO::FixedMaxPath enginePath(Py_To_String(engine["path"])); - if (enginePath.Compare(m_enginePath) == 0) - { - registerThis = false; - break; - } - } - } - - if (registerThis) - { - auto registrationResult = m_registration.attr("register")(m_enginePath.c_str()); - - AZ_Error("ProjectManagerWindow", registrationResult.cast() == 0, - "Registration of this engine failed!"); - } + // make sure the engine is registered + RegisterThisEngine(); return result == 0 && !PyErr_Occurred(); } catch ([[maybe_unused]] const std::exception& e) @@ -332,6 +311,37 @@ namespace O3DE::ProjectManager return !PyErr_Occurred(); } + bool PythonBindings::RegisterThisEngine() + { + bool registerThis = true; + + // check current engine path against all other registered engines + // to see if we are already registered + auto allEngines = m_registration.attr("get_engines")(); + if (pybind11::isinstance(allEngines)) + { + for (const auto& engine : allEngines) + { + AZ::IO::FixedMaxPath enginePath(Py_To_String(engine["path"])); + if (enginePath.Compare(m_enginePath) == 0) + { + registerThis = false; + break; + } + } + } + + bool result = true; + if (registerThis) + { + auto registrationResult = m_registration.attr("register")(m_enginePath.c_str()); + result = (registrationResult.cast() == 0); + } + + AZ_Error("ProjectManagerWindow", result, "Registration of this engine failed!"); + return result; + } + bool PythonBindings::ExecuteWithLock(AZStd::function executionCallback) { AZStd::lock_guard lock(m_lock); diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.h b/Code/Tools/ProjectManager/Source/PythonBindings.h index 892e13a65b..71616de4e0 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.h +++ b/Code/Tools/ProjectManager/Source/PythonBindings.h @@ -60,9 +60,11 @@ namespace O3DE::ProjectManager GemInfo GemInfoFromPath(pybind11::handle path); ProjectInfo ProjectInfoFromPath(pybind11::handle path); ProjectTemplateInfo ProjectTemplateInfoFromPath(pybind11::handle path); + bool RegisterThisEngine(); bool StartPython(); bool StopPython(); + AZ::IO::FixedMaxPath m_enginePath; pybind11::handle m_engineTemplate; AZStd::recursive_mutex m_lock;