1
0
Fork 0

Allow dragging custom node types onto array property editor

For example, an Array[MyScript] property now accepts any node with the
script MyScript on it. This works for Node and NodePath arrays alike,
and also with the @export_node_path annotation.
This commit is contained in:
Thomas ten Cate 2025-02-07 12:31:53 +01:00
parent 0c46089d1b
commit 11b3900a0e
1 changed files with 4 additions and 2 deletions

View File

@ -614,7 +614,8 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
ERR_FAIL_NULL_V_MSG(dropped_node, false, "Could not get the dropped node by its path.");
if (allowed_type != "NodePath") {
if (!ClassDB::is_parent_class(dropped_node->get_class_name(), allowed_type)) {
if (!ClassDB::is_parent_class(dropped_node->get_class_name(), allowed_type) &&
!EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, allowed_type)) {
// Fail if one of the nodes is not of allowed type.
return false;
}
@ -625,7 +626,8 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
if (!allowed_subtype_array.has(dropped_node->get_class_name())) {
// The dropped node type was not found in the allowed subtype array, we must check if it inherits one of them.
for (const String &ast : allowed_subtype_array) {
if (ClassDB::is_parent_class(dropped_node->get_class_name(), ast)) {
if (ClassDB::is_parent_class(dropped_node->get_class_name(), ast) ||
EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, ast)) {
is_drop_allowed = true;
break;
} else {