From 57df4e2905b59bf952c0764c7d964f5e6b55e580 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Wed, 23 Nov 2022 20:36:28 +0800 Subject: [PATCH] Fixed awake() and start() getting called before all objects are loaded when changing scenes --- SHADE_Engine/src/Scene/SHSceneManager.h | 9 +++++---- SHADE_Managed/src/Scripts/ScriptStore.cxx | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/SHADE_Engine/src/Scene/SHSceneManager.h b/SHADE_Engine/src/Scene/SHSceneManager.h index 8f03b352..8f553703 100644 --- a/SHADE_Engine/src/Scene/SHSceneManager.h +++ b/SHADE_Engine/src/Scene/SHSceneManager.h @@ -219,10 +219,11 @@ namespace SHADE static void Exit() noexcept; static std::string GetSceneName() noexcept; - static void SetCurrentSceneName(std::string const& sceneName) noexcept; - static AssetID GetCurrentSceneAssetID() noexcept; - //Only if scene doesn't exist, and scene asset id needs to be updated to the new one - static void SetCurrentSceneAssetID(AssetID const& newAssetID); + static void SetCurrentSceneName(std::string const& sceneName) noexcept; + static AssetID GetCurrentSceneAssetID() noexcept; + //Only if scene doesn't exist, and scene asset id needs to be updated to the new one + static void SetCurrentSceneAssetID(AssetID const& newAssetID); + static bool HasSceneChanged() noexcept { return sceneChanged; } }; diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index d3d989cc..3ffb72b2 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -74,8 +74,9 @@ namespace SHADE // Add the script in script->Initialize(GameObject(entity)); entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script); - if (Application::IsPlaying) + if (Application::IsPlaying && !SHSceneManager::HasSceneChanged()) { + // Only call immediately if we are in game and is not loading another scene script->Awake(); script->Start(); }