summaryrefslogtreecommitdiffstats
path: root/editor/scene_tree_dock.cpp
diff options
context:
space:
mode:
authorMarcin Nowak <marcin.j.nowak@gmail.com>2023-10-04 19:18:22 +0200
committerMarcin Nowak <marcin.j.nowak@gmail.com>2023-11-16 01:14:04 +0100
commit561fcf54a4dbb4cc51ff429edb2badc6c2bf87d3 (patch)
tree5fb616e77f96602a68fcc0743001c2bf2fc9d287 /editor/scene_tree_dock.cpp
parentfee6df76a2cf3d611f1b70655cc6d36b03e6e159 (diff)
downloadredot-engine-561fcf54a4dbb4cc51ff429edb2badc6c2bf87d3.tar.gz
Fix #82756: Save branch as scene saves children without owner set
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r--editor/scene_tree_dock.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index a94c978a1a..aca777ce33 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -2781,12 +2781,17 @@ void SceneTreeDock::_new_scene_from(String p_file) {
Node *base = selection.front()->get();
HashMap<const Node *, Node *> duplimap;
+ HashMap<const Node *, Node *> inverse_duplimap;
Node *copy = base->duplicate_from_editor(duplimap);
+ for (const KeyValue<const Node *, Node *> &item : duplimap) {
+ inverse_duplimap[item.value] = const_cast<Node *>(item.key);
+ }
+
if (copy) {
// Handle Unique Nodes.
for (int i = 0; i < copy->get_child_count(false); i++) {
- _set_node_owner_recursive(copy->get_child(i, false), copy);
+ _set_node_owner_recursive(copy->get_child(i, false), copy, inverse_duplimap);
}
// Root node cannot ever be unique name in its own Scene!
copy->set_unique_name_in_owner(false);
@@ -2820,13 +2825,18 @@ void SceneTreeDock::_new_scene_from(String p_file) {
}
}
-void SceneTreeDock::_set_node_owner_recursive(Node *p_node, Node *p_owner) {
- if (!p_node->get_owner()) {
- p_node->set_owner(p_owner);
+void SceneTreeDock::_set_node_owner_recursive(Node *p_node, Node *p_owner, const HashMap<const Node *, Node *> &p_inverse_duplimap) {
+ HashMap<const Node *, Node *>::ConstIterator E = p_inverse_duplimap.find(p_node);
+
+ if (E) {
+ const Node *original = E->value;
+ if (original->get_owner()) {
+ p_node->set_owner(p_owner);
+ }
}
for (int i = 0; i < p_node->get_child_count(false); i++) {
- _set_node_owner_recursive(p_node->get_child(i, false), p_owner);
+ _set_node_owner_recursive(p_node->get_child(i, false), p_owner, p_inverse_duplimap);
}
}