diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 868d8815d1..c2b20d798f 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -3241,16 +3241,14 @@ void Node::replace_by(RequiredParam rp_node, bool p_keep_groups) { emit_signal(SNAME("replacing_by"), p_node); - while (get_child_count()) { - Node *child = get_child(0); + // Move non-internal children to `p_node`. + while (get_child_count(false)) { + Node *child = get_child(0, false); remove_child(child); - if (!child->is_internal()) { - // Add the custom children to the p_node. - Node *child_owner = child->get_owner() == this ? p_node : child->get_owner(); - child->set_owner(nullptr); - p_node->add_child(child); - child->set_owner(child_owner); - } + Node *child_owner = child->get_owner() == this ? p_node : child->get_owner(); + child->set_owner(nullptr); + p_node->add_child(child); + child->set_owner(child_owner); } p_node->set_owner(owner);