Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | doppm |
I have a node named “Portal”
[Tool] public partial class Portal : Node2D { ... }
I expect to use this code to get the path of a Portal node in the scene
[Export(PropertyHint.NodePathValidTypes, hintString:"Portal")] NodePath nodePath;
but, it doesn’t work.
If I try to replace hintString:"Portal"
with hintString:"Node2D"
, it works.
but I can only select from all node2d types, not specify a certain type(eg. Portal)
I read the source code
// line 3688
bool EditorPropertyNodePath::is_drop_valid(const Dictionary &p_drag_data) const {
if (p_drag_data["type"] != "nodes") {
return false;
}
Array nodes = p_drag_data["nodes"];
if (nodes.size() != 1) {
return false;
}
Node *dropped_node = get_tree()->get_edited_scene_root()->get_node(nodes[0]);
ERR_FAIL_NULL_V(dropped_node, false);
if (valid_types.is_empty()) {
// No type requirements specified so any type is valid.
return true;
}
for (const StringName &E : valid_types) {
if (dropped_node->is_class(E) ||
EditorNode::get_singleton()->is_object_of_custom_type(dropped_node, E)) {
return true;
}
}
return false;
}
This code shows the editor does check the custom type.
Did I miss something important? I need help.