Skip to content

Commit e7d9df3

Browse files
committed
Assign base path when creating Resource
1 parent aef0065 commit e7d9df3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

editor/editor_resource_picker.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include "editor/audio_stream_preview.h"
3434
#include "editor/editor_help.h"
35+
#include "editor/editor_inspector.h"
3536
#include "editor/editor_node.h"
3637
#include "editor/editor_resource_preview.h"
3738
#include "editor/editor_settings.h"
@@ -486,6 +487,7 @@ void EditorResourcePicker::_edit_menu_cbk(int p_which) {
486487

487488
Resource *resp = Object::cast_to<Resource>(obj);
488489
ERR_BREAK(!resp);
490+
resp->set_path(_get_owner_path() + "::"); // Assign a base path for built-in Resources.
489491

490492
EditorNode::get_editor_data().instantiate_object_properties(obj);
491493

@@ -579,6 +581,32 @@ void EditorResourcePicker::_button_input(const Ref<InputEvent> &p_event) {
579581
}
580582
}
581583

584+
String EditorResourcePicker::_get_owner_path() const {
585+
EditorProperty *property = Object::cast_to<EditorProperty>(get_parent());
586+
if (!property) {
587+
return String();
588+
}
589+
Object *obj = property->get_edited_object();
590+
591+
Node *node = Object::cast_to<Node>(obj);
592+
if (node) {
593+
if (node->get_scene_file_path().is_empty()) {
594+
node = node->get_owner();
595+
}
596+
if (node) {
597+
return node->get_scene_file_path();
598+
}
599+
return String();
600+
}
601+
602+
Resource *res = Object::cast_to<Resource>(obj);
603+
if (res && !res->is_built_in()) {
604+
return res->get_path();
605+
}
606+
// TODO: It would be nice to handle deeper Resource nesting.
607+
return String();
608+
}
609+
582610
String EditorResourcePicker::_get_resource_type(const Ref<Resource> &p_resource) const {
583611
if (p_resource.is_null()) {
584612
return String();

editor/editor_resource_picker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class EditorResourcePicker : public HBoxContainer {
9999
void _button_draw();
100100
void _button_input(const Ref<InputEvent> &p_event);
101101

102+
String _get_owner_path() const;
102103
String _get_resource_type(const Ref<Resource> &p_resource) const;
103104
void _ensure_allowed_types() const;
104105
bool _is_drop_valid(const Dictionary &p_drag_data) const;

0 commit comments

Comments
 (0)