Merge pull request #118037 from mihe/existing-uid-import

Fix newly imported files not having existing UID assigned
This commit is contained in:
Thaddeus Crews
2026-04-07 18:21:50 -05:00
+13 -2
View File
@@ -920,15 +920,26 @@ bool EditorFileSystem::_update_scan_actions() {
const String new_file_path = ia.dir->get_file_path(idx);
const ResourceUID::ID existing_id = ResourceLoader::get_resource_uid(new_file_path);
if (existing_id != ResourceUID::INVALID_ID) {
const String old_path = ResourceUID::get_singleton()->get_id_path(existing_id);
if (old_path != new_file_path && FileAccess::exists(old_path)) {
const bool id_known = ResourceUID::get_singleton()->has_id(existing_id);
const String old_path = id_known ? ResourceUID::get_singleton()->get_id_path(existing_id) : String();
if (id_known && old_path != new_file_path && FileAccess::exists(old_path)) {
const ResourceUID::ID new_id = ResourceUID::get_singleton()->create_id_for_path(new_file_path);
ResourceUID::get_singleton()->add_id(new_id, new_file_path);
ResourceSaver::set_uid(new_file_path, new_id);
WARN_PRINT(vformat("Duplicate UID detected for Resource at \"%s\".\nOld Resource path: \"%s\". The new file UID was changed automatically.", new_file_path, old_path));
ia.new_file->uid = new_id;
} else {
// Re-assign the UID to file, just in case it was pulled from cache.
ResourceSaver::set_uid(new_file_path, existing_id);
if (id_known) {
ResourceUID::get_singleton()->set_id(existing_id, new_file_path);
} else {
ResourceUID::get_singleton()->add_id(existing_id, new_file_path);
}
ia.new_file->uid = existing_id;
}
} else if (ResourceLoader::should_create_uid_file(new_file_path)) {
Ref<FileAccess> f = FileAccess::open(new_file_path + ".uid", FileAccess::WRITE);