Merge pull request #75938 from YuriSizov/editor-no-spammy-icons

Prevent errors in the Inspector when looking for script icons
This commit is contained in:
Rémi Verschelde 2023-04-11 19:41:07 +02:00
commit bba753db0d
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 13 additions and 9 deletions

View File

@ -2759,26 +2759,30 @@ void EditorInspector::update_tree() {
doc_name = p.name; doc_name = p.name;
// Use category's owner script to update some of its information. // Use category's owner script to update some of its information.
if (!EditorNode::get_editor_data().is_type_recognized(type) && p.hint_string.length() && FileAccess::exists(p.hint_string)) { if (!EditorNode::get_editor_data().is_type_recognized(type) && p.hint_string.length() && ResourceLoader::exists(p.hint_string)) {
StringName script_name;
Ref<Script> scr = ResourceLoader::load(p.hint_string, "Script"); Ref<Script> scr = ResourceLoader::load(p.hint_string, "Script");
if (scr.is_valid()) { if (scr.is_valid()) {
script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path()); StringName script_name = EditorNode::get_editor_data().script_class_get_name(scr->get_path());
// Update the docs reference and the label based on the script. // Update the docs reference and the label based on the script.
Vector<DocData::ClassDoc> docs = scr->get_documentation(); Vector<DocData::ClassDoc> docs = scr->get_documentation();
if (!docs.is_empty()) { if (!docs.is_empty()) {
doc_name = docs[0].name; doc_name = docs[0].name;
} }
if (script_name != StringName() && label != script_name) { if (script_name != StringName()) {
label = script_name; label = script_name;
} }
}
// Find the corresponding icon. // Find the icon corresponding to the script.
category->icon = EditorNode::get_singleton()->get_class_icon(script_name, "Object"); if (script_name != StringName()) {
} else if (!type.is_empty()) { category->icon = EditorNode::get_singleton()->get_class_icon(script_name, "Object");
} else {
category->icon = EditorNode::get_singleton()->get_object_icon(scr.ptr(), "Object");
}
}
}
if (category->icon.is_null() && !type.is_empty()) {
category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object"); category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
} }