Merge pull request #36301 from KoBeWi/daddy_node
Add reparent methods to Node
This commit is contained in:
@ -1439,6 +1439,18 @@ TypedArray<Node> Node::find_children(const String &p_pattern, const String &p_ty
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Node::reparent(Node *p_parent, bool p_keep_global_transform) {
|
||||
ERR_FAIL_NULL(p_parent);
|
||||
ERR_FAIL_NULL_MSG(data.parent, "Node needs a parent to be reparented.");
|
||||
|
||||
if (p_parent == data.parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
data.parent->remove_child(this);
|
||||
p_parent->add_child(this);
|
||||
}
|
||||
|
||||
Node *Node::get_parent() const {
|
||||
return data.parent;
|
||||
}
|
||||
@ -2784,6 +2796,7 @@ void Node::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_name"), &Node::get_name);
|
||||
ClassDB::bind_method(D_METHOD("add_child", "node", "force_readable_name", "internal"), &Node::add_child, DEFVAL(false), DEFVAL(0));
|
||||
ClassDB::bind_method(D_METHOD("remove_child", "node"), &Node::remove_child);
|
||||
ClassDB::bind_method(D_METHOD("reparent", "new_parent", "keep_global_transform"), &Node::reparent, DEFVAL(true));
|
||||
ClassDB::bind_method(D_METHOD("get_child_count", "include_internal"), &Node::get_child_count, DEFVAL(false)); // Note that the default value bound for include_internal is false, while the method is declared with true. This is because internal nodes are irrelevant for GDSCript.
|
||||
ClassDB::bind_method(D_METHOD("get_children", "include_internal"), &Node::_get_children, DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("get_child", "idx", "include_internal"), &Node::get_child, DEFVAL(false));
|
||||
|
||||
Reference in New Issue
Block a user