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

This commit is contained in:
Kah Wei 2022-11-23 20:36:28 +08:00
parent c32aa1e00c
commit 57df4e2905
2 changed files with 7 additions and 5 deletions

View File

@ -223,6 +223,7 @@ namespace SHADE
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; }
};

View File

@ -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();
}