diff --git a/Source/Editor/Windows/Assets/JsonAssetWindow.cs b/Source/Editor/Windows/Assets/JsonAssetWindow.cs index da463c501..779c8cc4e 100644 --- a/Source/Editor/Windows/Assets/JsonAssetWindow.cs +++ b/Source/Editor/Windows/Assets/JsonAssetWindow.cs @@ -18,6 +18,7 @@ namespace FlaxEditor.Windows.Assets private readonly CustomEditorPresenter _presenter; private readonly ToolStripButton _saveButton; private object _object; + private bool _isRegisteredForScriptsReload; /// public JsonAssetWindow(Editor editor, AssetItem item) @@ -43,7 +44,6 @@ namespace FlaxEditor.Windows.Assets private void OnScriptsReloadBegin() { Close(); - ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin; } /// @@ -83,8 +83,11 @@ namespace FlaxEditor.Windows.Assets ClearEditedFlag(); // Auto-close on scripting reload if json asset is from game scripts (it might be reloaded) - if (_object != null && FlaxEngine.Scripting.IsTypeFromGameScripts(_object.GetType())) + if (_object != null && FlaxEngine.Scripting.IsTypeFromGameScripts(_object.GetType()) && !_isRegisteredForScriptsReload) + { + _isRegisteredForScriptsReload = true; ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin; + } base.OnAssetLoaded(); } @@ -98,5 +101,17 @@ namespace FlaxEditor.Windows.Assets base.OnItemReimported(item); } + + /// + public override void OnDestroy() + { + if (_isRegisteredForScriptsReload) + { + _isRegisteredForScriptsReload = false; + ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin; + } + + base.OnDestroy(); + } } } diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index 8b8d4ae07..613427d9f 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -496,14 +496,8 @@ public: // - load scenes (from temporary files) // Note: we don't want to override original scene files - // If no scene loaded just reload scripting - if (!Level::IsAnySceneLoaded()) - { - // Reload scripting - LOG(Info, "No scenes loaded, performing fast scripts reload"); - Scripting::Reload(false); - return false; - } + LOG(Info, "Scripts reloading start"); + const auto startTime = DateTime::NowUTC(); // Cache data struct SceneData @@ -538,8 +532,6 @@ public: scenes[i].Init(Level::Scenes[i]); // Fire event - LOG(Info, "Scripts reloading start"); - const auto startTime = DateTime::NowUTC(); Level::ScriptsReloadStart(); // Save scenes (to memory) @@ -566,9 +558,10 @@ public: Scripting::Reload(); // Restore scenes (from memory) - LOG(Info, "Loading temporary scenes"); for (int32 i = 0; i < scenesCount; i++) { + LOG(Info, "Restoring scene {0}", scenes[i].Name); + // Parse json const auto& sceneData = scenes[i].Data; ISerializable::SerializeDocument document; @@ -590,8 +583,9 @@ public: scenes.Resize(0); // Initialize scenes (will link references and create managed objects using new assembly) - LOG(Info, "Prepare scene objects"); + if (Level::Scenes.HasItems()) { + LOG(Info, "Prepare scene objects"); SceneBeginData beginData; for (int32 i = 0; i < Level::Scenes.Count(); i++) { @@ -601,8 +595,7 @@ public: } // Fire event - const auto endTime = DateTime::NowUTC(); - LOG(Info, "Scripts reloading end. Total time: {0}ms", static_cast((endTime - startTime).GetTotalMilliseconds())); + LOG(Info, "Scripts reloading end. Total time: {0}ms", static_cast((DateTime::NowUTC() - startTime).GetTotalMilliseconds())); Level::ScriptsReloadEnd(); return false;