Fixed awake() and start() getting called before all objects are loaded when changing scenes #266

Merged
Pycorax merged 1 commits from Fix-AwakeLater into main 2022-11-23 20:37:46 +08:00
2 changed files with 7 additions and 5 deletions
Showing only changes of commit 57df4e2905 - Show all commits

View File

@ -219,10 +219,11 @@ namespace SHADE
static void Exit() noexcept; static void Exit() noexcept;
static std::string GetSceneName() noexcept; static std::string GetSceneName() noexcept;
static void SetCurrentSceneName(std::string const& sceneName) noexcept; static void SetCurrentSceneName(std::string const& sceneName) noexcept;
static AssetID GetCurrentSceneAssetID() noexcept; static AssetID GetCurrentSceneAssetID() noexcept;
//Only if scene doesn't exist, and scene asset id needs to be updated to the new one //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 SetCurrentSceneAssetID(AssetID const& newAssetID);
static bool HasSceneChanged() noexcept { return sceneChanged; }
}; };

View File

@ -74,8 +74,9 @@ namespace SHADE
// Add the script in // Add the script in
script->Initialize(GameObject(entity)); script->Initialize(GameObject(entity));
entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script); 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->Awake();
script->Start(); script->Start();
} }