From dd5cc4bbd1e085b459c6e03712a342c70831e6c2 Mon Sep 17 00:00:00 2001 From: kleonc <9283098+kleonc@users.noreply.github.com> Date: Sat, 14 Feb 2026 14:10:39 +0100 Subject: [PATCH] Don't remove internal nodes in Node::replace_by --- scene/main/node.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 3eb5cb6659..52bb7c09f7 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -3245,16 +3245,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);