From e7d9df33a5a4ec3c151a8d793f648ceec405130b Mon Sep 17 00:00:00 2001 From: kobewi Date: Fri, 23 May 2025 16:06:15 +0200 Subject: [PATCH] Assign base path when creating Resource --- editor/editor_resource_picker.cpp | 28 ++++++++++++++++++++++++++++ editor/editor_resource_picker.h | 1 + 2 files changed, 29 insertions(+) diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 4ea0a08a811..a89074ae346 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -32,6 +32,7 @@ #include "editor/audio_stream_preview.h" #include "editor/editor_help.h" +#include "editor/editor_inspector.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" #include "editor/editor_settings.h" @@ -486,6 +487,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) { Resource *resp = Object::cast_to(obj); ERR_BREAK(!resp); + resp->set_path(_get_owner_path() + "::"); // Assign a base path for built-in Resources. EditorNode::get_editor_data().instantiate_object_properties(obj); @@ -579,6 +581,32 @@ void EditorResourcePicker::_button_input(const Ref &p_event) { } } +String EditorResourcePicker::_get_owner_path() const { + EditorProperty *property = Object::cast_to(get_parent()); + if (!property) { + return String(); + } + Object *obj = property->get_edited_object(); + + Node *node = Object::cast_to(obj); + if (node) { + if (node->get_scene_file_path().is_empty()) { + node = node->get_owner(); + } + if (node) { + return node->get_scene_file_path(); + } + return String(); + } + + Resource *res = Object::cast_to(obj); + if (res && !res->is_built_in()) { + return res->get_path(); + } + // TODO: It would be nice to handle deeper Resource nesting. + return String(); +} + String EditorResourcePicker::_get_resource_type(const Ref &p_resource) const { if (p_resource.is_null()) { return String(); diff --git a/editor/editor_resource_picker.h b/editor/editor_resource_picker.h index a91a4dcb589..9369516b7f5 100644 --- a/editor/editor_resource_picker.h +++ b/editor/editor_resource_picker.h @@ -99,6 +99,7 @@ class EditorResourcePicker : public HBoxContainer { void _button_draw(); void _button_input(const Ref &p_event); + String _get_owner_path() const; String _get_resource_type(const Ref &p_resource) const; void _ensure_allowed_types() const; bool _is_drop_valid(const Dictionary &p_drag_data) const;