Repository: godotengine/godot (language: cpp)

Issue:
The UID metadata file is dropped when renaming an asset outside the Editor
### Tested versions

v4.4.stable.mono.official [4c311cbee]

### System information

Godot v4.4.stable.mono - Windows 10 (build 19044) - Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Laptop GPU (NVIDIA; 32.0.15.7270) - AMD Ryzen 9 5900HS with Radeon Graphics (16 threads)

### Issue description

The Godot Editor struggles to detect unexpected external file name changes if the UID file is not renamed at the same time.

https://github.com/user-attachments/assets/ff627707-6000-4215-aad7-b9b16aa18b7f

### Steps to reproduce

1. Create a new empty project.  
2. Create a GDScript file.  
3. Rename this GDScript file outside of the editor.  
4. Return to the editor.  
5. Note that the editor has deleted the original UID file but has not generated a new one for the GDScript file with the new name.  

### Minimal reproduction project (MRP)

An empty project


Discussion / hints:
There is a report about deleting an imported image not invalidating the backing `.import` and `ctex` files as well; however, [the video](https://www.bilibili.com/video/BV1jFQrY1E19) the author speaks in Chinese, and I can't make an MRP about it.

It tastes like there is a caching issue, either because of our changes to the file system scanning strategy or the new UID-based file locator.

Fix patch:
diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp
index f823900744f8..df0612450f6c 100644
--- a/editor/editor_file_system.cpp
+++ b/editor/editor_file_system.cpp
@@ -913,6 +913,12 @@ bool EditorFileSystem::_update_scan_actions() {
 						// Re-assign the UID to file, just in case it was pulled from cache.
 						ResourceSaver::set_uid(new_file_path, existing_id);
 					}
+				} else if (ResourceLoader::should_create_uid_file(new_file_path)) {
+					Ref<FileAccess> f = FileAccess::open(new_file_path + ".uid", FileAccess::WRITE);
+					if (f.is_valid()) {
+						ia.new_file->uid = ResourceUID::get_singleton()->create_id();
+						f->store_line(ResourceUID::get_singleton()->id_to_text(ia.new_file->uid));
+					}
 				}
 
 				if (ClassDB::is_parent_class(ia.new_file->type, SNAME("Script"))) {


Test patch: