editor: warn on UID duplicates

This commonly occurs when files are copied outside of the editor and don't get new UIDs.

Restricting this warning to first_scan since it's we want to exclude the case of files being moved after initial load which is harder to handle.

Addresses https://github.com/godotengine/godot-proposals/discussions/8949
This commit is contained in:
David Nikdel 2024-06-10 08:34:25 -04:00
parent 32eba1ee17
commit 5122a3e3b0

View File

@ -961,6 +961,14 @@ void EditorFileSystem::_scan_new_dir(EditorFileSystemDirectory *p_dir, Ref<DirAc
if (fi->uid != ResourceUID::INVALID_ID) {
if (ResourceUID::get_singleton()->has_id(fi->uid)) {
// Restrict UID dupe warning to first-scan since we know there are no file moves going on yet.
if (first_scan) {
// Warn if we detect files with duplicate UIDs.
const String other_path = ResourceUID::get_singleton()->get_id_path(fi->uid);
if (other_path != path) {
WARN_PRINT(vformat("UID duplicate detected between %s and %s.", path, other_path));
}
}
ResourceUID::get_singleton()->set_id(fi->uid, path);
} else {
ResourceUID::get_singleton()->add_id(fi->uid, path);