diff --git a/SHADE_Managed/src/Scripts/ScriptStore.cxx b/SHADE_Managed/src/Scripts/ScriptStore.cxx index 3ffb72b2..a5a0ebc7 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.cxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.cxx @@ -74,7 +74,7 @@ namespace SHADE // Add the script in script->Initialize(GameObject(entity)); entityScriptList->Insert(System::Math::Clamp(index, 0, entityScriptList->Count), script); - if (Application::IsPlaying && !SHSceneManager::HasSceneChanged()) + if (Application::IsPlaying && !isDeserialising) { // Only call immediately if we are in game and is not loading another scene script->Awake(); @@ -423,6 +423,8 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ void ScriptStore::Init() { + isDeserialising = false; + // Create an enumerable list of script types refreshScriptTypeList(); // Get stored methods for interop variants of functions @@ -724,6 +726,10 @@ namespace SHADE bool ScriptStore::DeserialiseScripts(Entity entity, System::IntPtr yamlNodePtr) { SAFE_NATIVE_CALL_BEGIN + + // Flag that deserialization processs is ongoing + isDeserialising = true; + // Convert to pointer YAML::Node* yamlNode = reinterpret_cast(yamlNodePtr.ToPointer()); @@ -765,9 +771,16 @@ namespace SHADE Debug::LogWarning("[ScriptStore] Script with unloaded type detected, skipping."); } } + + // Unset flag for deserialization process + isDeserialising = false; + return true; SAFE_NATIVE_CALL_END_N("SHADE_Managed.ScriptStore") + + // Unset flag for deserialization process + isDeserialising = false; return false; } diff --git a/SHADE_Managed/src/Scripts/ScriptStore.hxx b/SHADE_Managed/src/Scripts/ScriptStore.hxx index 78f8c787..f31836d8 100644 --- a/SHADE_Managed/src/Scripts/ScriptStore.hxx +++ b/SHADE_Managed/src/Scripts/ScriptStore.hxx @@ -337,6 +337,7 @@ namespace SHADE static ScriptSet disposalQueue; static System::Collections::Generic::IEnumerable^ scriptTypeList; static System::Reflection::MethodInfo^ addScriptMethod; + static bool isDeserialising; /*-----------------------------------------------------------------------------*/ /* Helper Functions */