From b6f12be917effaad6e35d955e8edf2d67ac64fe5 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 21 Aug 2026 13:32:12 +0300 Subject: [PATCH] Fix scripts/content files getting deleted after file modifications Some editors like Visual Studio saves the modified file to a temporary file, deletes the original file and renames the temporary file back to original filename, which rarely causes the editor to detect it as a file deletion action by user. --- .../Editor/Modules/ContentDatabaseModule.cs | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Source/Editor/Modules/ContentDatabaseModule.cs b/Source/Editor/Modules/ContentDatabaseModule.cs index 237c95792..76c1180e6 100644 --- a/Source/Editor/Modules/ContentDatabaseModule.cs +++ b/Source/Editor/Modules/ContentDatabaseModule.cs @@ -748,21 +748,27 @@ namespace FlaxEditor.Modules if (item.Path.Contains(".Build.cs", StringComparison.Ordinal) && item.ItemType == ContentItemType.Script) Editor.Instance.CodeEditing.RemoveModule(item.Path); - // Check if it's an asset - if (item.IsAsset) - { - // Delete asset by using content pool - FlaxEngine.Content.DeleteAsset(path); - } - else if (item is ScriptItem) - { - FlaxEngine.Content.DeleteScript(path); - } - else if (deletedByUser) - { - // Delete file - if (File.Exists(path)) - File.Delete(path); + // Delete asset file only if it was explicitly deleted by the user. + // Some applications might modify the file by deleting the original and replacing + // it with a new file which sometimes is caught in the middle of these operations. + if (deletedByUser) + { + // Check if it's an asset + if (item.IsAsset) + { + // Delete asset by using content pool + FlaxEngine.Content.DeleteAsset(path); + } + else if (item is ScriptItem) + { + FlaxEngine.Content.DeleteScript(path); + } + else + { + // Delete file + if (File.Exists(path)) + File.Delete(path); + } } // Unlink from the parent