From f320274ca302c55005daa76bc561000c745fb8e0 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sat, 12 Jul 2025 18:58:13 +0200 Subject: [PATCH] Improve Paste as Unique option --- editor/inspector/editor_resource_picker.cpp | 33 ++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/editor/inspector/editor_resource_picker.cpp b/editor/inspector/editor_resource_picker.cpp index 141c05498eb..898a067cff6 100644 --- a/editor/inspector/editor_resource_picker.cpp +++ b/editor/inspector/editor_resource_picker.cpp @@ -49,6 +49,17 @@ #include "scene/resources/gradient_texture.h" #include "scene/resources/image_texture.h" +static bool _has_sub_resources(const Ref &p_res) { + List property_list; + p_res->get_property_list(&property_list); + for (const PropertyInfo &p : property_list) { + if (p.type == Variant::OBJECT && p.hint == PROPERTY_HINT_RESOURCE_TYPE && !(p.usage & PROPERTY_USAGE_NEVER_DUPLICATE) && p_res->get(p.name).get_validated_object()) { + return true; + } + } + return false; +} + void EditorResourcePicker::_update_resource() { String resource_path; if (edited_resource.is_valid() && edited_resource->get_path().is_resource_file()) { @@ -237,17 +248,7 @@ void EditorResourcePicker::_update_menu_items() { } edit_menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Make Unique"), OBJ_MENU_MAKE_UNIQUE); - // Check whether the resource has subresources. - List property_list; - edited_resource->get_property_list(&property_list); - bool has_subresources = false; - for (PropertyInfo &p : property_list) { - if ((p.type == Variant::OBJECT) && (p.hint == PROPERTY_HINT_RESOURCE_TYPE) && (p.name != "script") && ((Object *)edited_resource->get(p.name) != nullptr)) { - has_subresources = true; - break; - } - } - if (has_subresources) { + if (_has_sub_resources(edited_resource)) { edit_menu->add_icon_item(get_editor_theme_icon(SNAME("Duplicate")), TTR("Make Unique (Recursive)"), OBJ_MENU_MAKE_UNIQUE_RECURSIVE); } @@ -464,9 +465,13 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { case OBJ_MENU_PASTE_AS_UNIQUE: { edited_resource = EditorSettings::get_singleton()->get_resource_clipboard(); - // Use the recursive version when using Paste as Unique. - // This will show up a dialog to select which resources to make unique. - _edit_menu_cbk(OBJ_MENU_MAKE_UNIQUE_RECURSIVE); + if (_has_sub_resources(edited_resource)) { + // Use the recursive version when the Resource has sub-resources. + // This will show up a dialog to select which resources to make unique. + _edit_menu_cbk(OBJ_MENU_MAKE_UNIQUE_RECURSIVE); + } else { + _edit_menu_cbk(OBJ_MENU_MAKE_UNIQUE); + } } break; case OBJ_MENU_SHOW_IN_FILE_SYSTEM: {