diff --git a/editor/inspector/editor_inspector.cpp b/editor/inspector/editor_inspector.cpp index 6999231659..87c901d60d 100644 --- a/editor/inspector/editor_inspector.cpp +++ b/editor/inspector/editor_inspector.cpp @@ -43,6 +43,7 @@ #include "editor/inspector/add_metadata_dialog.h" #include "editor/inspector/editor_properties.h" #include "editor/inspector/editor_property_name_processor.h" +#include "editor/inspector/editor_resource_picker.h" #include "editor/inspector/multi_node_edit.h" #include "editor/script/script_editor_plugin.h" #include "editor/settings/editor_feature_profile.h" @@ -1417,6 +1418,13 @@ void EditorProperty::menu_option(int p_option) { EditorInspector::set_property_clipboard(object->get(property)); } break; case MENU_PASTE_VALUE: { + EditorPropertyResource *epr = Object::cast_to(this); + if (epr) { + const Ref res = InspectorDock::get_inspector_singleton()->get_property_clipboard(); + if (res.is_valid() && !epr->get_resource_picker()->is_resource_allowed(res)) { + return; + } + } emit_changed(property, EditorInspector::get_property_clipboard()); } break; case MENU_COPY_PROPERTY_PATH: { diff --git a/editor/inspector/editor_properties.h b/editor/inspector/editor_properties.h index f223123802..e8b1b2b493 100644 --- a/editor/inspector/editor_properties.h +++ b/editor/inspector/editor_properties.h @@ -764,6 +764,7 @@ protected: public: virtual void update_property() override; void setup(Object *p_object, const String &p_path, const String &p_base_type); + EditorResourcePicker *get_resource_picker() const { return resource_picker; } void collapse_all_folding() override; void expand_all_folding() override; diff --git a/editor/inspector/editor_resource_picker.cpp b/editor/inspector/editor_resource_picker.cpp index cb6baf63f1..4994cc5481 100644 --- a/editor/inspector/editor_resource_picker.cpp +++ b/editor/inspector/editor_resource_picker.cpp @@ -1156,11 +1156,9 @@ Vector EditorResourcePicker::get_allowed_types() const { return types; } -void EditorResourcePicker::set_edited_resource(Ref p_resource) { +bool EditorResourcePicker::is_resource_allowed(const Ref &p_resource) { if (p_resource.is_null()) { - edited_resource = Ref(); - _update_resource(); - return; + return true; } if (!base_type.is_empty()) { @@ -1175,10 +1173,21 @@ void EditorResourcePicker::set_edited_resource(Ref p_resource) { } if (!is_custom && !_is_type_valid(p_resource->get_class(), allowed_types)) { - String class_str = (custom_class == StringName() ? p_resource->get_class() : vformat("%s (%s)", custom_class, p_resource->get_class())); - ERR_FAIL_MSG(vformat("Failed to set a resource of the type '%s' because this EditorResourcePicker only accepts '%s' and its derivatives.", class_str, base_type)); + return false; } } + return true; +} + +void EditorResourcePicker::set_edited_resource(Ref p_resource) { + if (!is_resource_allowed(p_resource)) { + StringName custom_class; + if (p_resource->get_script()) { + custom_class = EditorNode::get_singleton()->get_object_custom_type_name(p_resource->get_script()); + } + const String class_str = (custom_class.is_empty() ? p_resource->get_class() : vformat("%s (%s)", custom_class, p_resource->get_class())); + ERR_FAIL_MSG(vformat("Failed to set a resource of the type '%s' because this EditorResourcePicker only accepts '%s' and its derivatives.", class_str, base_type)); + } set_edited_resource_no_check(p_resource); } diff --git a/editor/inspector/editor_resource_picker.h b/editor/inspector/editor_resource_picker.h index 18b5a0d921..c76e2f73b5 100644 --- a/editor/inspector/editor_resource_picker.h +++ b/editor/inspector/editor_resource_picker.h @@ -140,6 +140,7 @@ public: String get_base_type() const; Vector get_allowed_types() const; + bool is_resource_allowed(const Ref &p_resource); void set_edited_resource(Ref p_resource); void set_edited_resource_no_check(Ref p_resource); Ref get_edited_resource();