Fix wrong children range when duplicating node

This commit is contained in:
kobewi
2025-05-11 17:32:29 +02:00
parent 19bb18716e
commit 258062e312
2 changed files with 33 additions and 8 deletions

View File

@ -3000,18 +3000,18 @@ Node *Node::_duplicate(int p_flags, HashMap<const Node *, Node *> *r_duplimap) c
}
for (int i = 0; i < get_child_count(false); i++) {
if (instantiated && get_child(i)->data.owner == this) {
if (instantiated && get_child(i, false)->data.owner == this) {
continue; //part of instance
}
Node *dup = get_child(i)->_duplicate(p_flags, r_duplimap);
Node *dup = get_child(i, false)->_duplicate(p_flags, r_duplimap);
if (!dup) {
memdelete(node);
return nullptr;
}
node->add_child(dup);
if (i < node->get_child_count() - 1) {
if (i < node->get_child_count(false) - 1) {
node->move_child(dup, i);
}
}
@ -3030,9 +3030,9 @@ Node *Node::_duplicate(int p_flags, HashMap<const Node *, Node *> *r_duplimap) c
}
parent->add_child(dup);
int pos = E->get_index();
int pos = E->get_index(false);
if (pos < parent->get_child_count() - 1) {
if (pos < parent->get_child_count(false) - 1) {
parent->move_child(dup, pos);
}
}