From 261129496c17bee57dbd9018b3649cda7c766cb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Mon, 13 Nov 2023 09:44:07 +0800 Subject: [PATCH] Fix duplicating sub-scene may get two copies of internal node Previously, internal node might be mistaken for `hidden_root` and be duplicated again. Exclude those internal nodes to avoid this case, unless the owner is set intentionally. (cherry picked from commit f19c4191260041eed72daa8a2633187e71500d10) --- scene/main/node.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 74dce01d9a0..41056c86e8b 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2510,6 +2510,11 @@ Node *Node::_duplicate(int p_flags, HashMap *r_duplimap) c for (List::Element *N = node_tree.front(); N; N = N->next()) { for (int i = 0; i < N->get()->get_child_count(); ++i) { Node *descendant = N->get()->get_child(i); + + if (!descendant->get_owner()) { + continue; // Internal nodes or nodes added by scripts. + } + // Skip nodes not really belonging to the instantiated hierarchy; they'll be processed normally later // but remember non-instantiated nodes that are hidden below instantiated ones if (!instance_roots.has(descendant->get_owner())) {