Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing UID handling in Dependency Editor #73131

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions editor/dependency_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,16 @@ void DependencyEditor::_update_list() {

ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(path);
if (uid != ResourceUID::INVALID_ID) {
// dependency is in uid format, obtain proper path
ERR_CONTINUE(!ResourceUID::get_singleton()->has_id(uid));

path = ResourceUID::get_singleton()->get_id_path(uid);
// Dependency is in uid format, obtain proper path.
if (ResourceUID::get_singleton()->has_id(uid)) {
path = ResourceUID::get_singleton()->get_id_path(uid);
} else if (n.get_slice_count("::") >= 3) {
// If uid can't be found, try to use fallback path.
path = n.get_slice("::", 2);
} else {
ERR_PRINT("Invalid dependency UID and fallback path.");
continue;
}
}

String name = path.get_file();
Expand Down
12 changes: 10 additions & 2 deletions scene/resources/resource_format_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,26 +851,34 @@ void ResourceLoaderText::get_dependencies(Ref<FileAccess> p_f, List<String> *p_d

String path = next_tag.fields["path"];
String type = next_tag.fields["type"];
String fallback_path;

bool using_uid = false;
if (next_tag.fields.has("uid")) {
//if uid exists, return uid in text format, not the path
// If uid exists, return uid in text format, not the path.
String uidt = next_tag.fields["uid"];
ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(uidt);
if (uid != ResourceUID::INVALID_ID) {
fallback_path = path; // Used by Dependency Editor, in case uid path fails.
path = ResourceUID::get_singleton()->id_to_text(uid);
using_uid = true;
}
}

if (!using_uid && !path.contains("://") && path.is_relative_path()) {
// path is relative to file being loaded, so convert to a resource path
// Path is relative to file being loaded, so convert to a resource path.
path = ProjectSettings::get_singleton()->localize_path(local_path.get_base_dir().path_join(path));
}

if (p_add_types) {
path += "::" + type;
}
if (!fallback_path.is_empty()) {
if (!p_add_types) {
path += "::"; // Ensure that path comes third, even if there is no type.
}
path += "::" + fallback_path;
}

p_dependencies->push_back(path);

Expand Down