Skip to content

Commit de1499c

Browse files
committed
Merge pull request godotengine#100927 from KoBeWi/yeah,_uids
Assign new UID when duplicating file externally
2 parents 709f2e1 + 8e9c4e0 commit de1499c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

editor/editor_file_system.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,11 +843,26 @@ bool EditorFileSystem::_update_scan_actions() {
843843

844844
fs_changed = true;
845845

846+
const String new_file_path = ia.dir->get_file_path(idx);
847+
const ResourceUID::ID existing_id = ResourceLoader::get_resource_uid(new_file_path);
848+
if (existing_id != ResourceUID::INVALID_ID) {
849+
const String old_path = ResourceUID::get_singleton()->get_id_path(existing_id);
850+
if (old_path != new_file_path && FileAccess::exists(old_path)) {
851+
const ResourceUID::ID new_id = ResourceUID::get_singleton()->create_id();
852+
ResourceUID::get_singleton()->add_id(new_id, new_file_path);
853+
ResourceSaver::set_uid(new_file_path, new_id);
854+
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));
855+
} else {
856+
// Re-assign the UID to file, just in case it was pulled from cache.
857+
ResourceSaver::set_uid(new_file_path, existing_id);
858+
}
859+
}
860+
846861
if (ClassDB::is_parent_class(ia.new_file->type, SNAME("Script"))) {
847-
_queue_update_script_class(ia.dir->get_file_path(idx), ia.new_file->type, ia.new_file->script_class_name, ia.new_file->script_class_extends, ia.new_file->script_class_icon_path);
862+
_queue_update_script_class(new_file_path, ia.new_file->type, ia.new_file->script_class_name, ia.new_file->script_class_extends, ia.new_file->script_class_icon_path);
848863
}
849864
if (ia.new_file->type == SNAME("PackedScene")) {
850-
_queue_update_scene_groups(ia.dir->get_file_path(idx));
865+
_queue_update_scene_groups(new_file_path);
851866
}
852867

853868
} break;

0 commit comments

Comments
 (0)