diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 86bfab0b6d6..4c0ebd273c2 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" @@ -496,6 +497,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); @@ -589,6 +591,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 856d04503c0..a08a93d197f 100644 --- a/editor/editor_resource_picker.h +++ b/editor/editor_resource_picker.h @@ -101,6 +101,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;