Merge pull request #266 from SHADE-DP/Fix-AwakeLater

Fixed awake() and start() getting called before all objects are loaded when changing scenes
This commit is contained in:
XiaoQiDigipen 2022-11-23 20:37:46 +08:00 committed by GitHub
commit acc13fd0e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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();
}