summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaracenOne <SaracenOne@gmail.com>2023-02-22 18:07:36 +0000
committerSaracenOne <SaracenOne@gmail.com>2023-02-22 18:21:14 +0000
commit7bbd7833de9fced633f247a15132a085b2700f78 (patch)
treed0f0454470fa9da8cf384b34e137371e239a1b73
parent999bb91dc670882742bb28c698297f110ca3fd0b (diff)
Fix ownership bug on ancestor nodes when scene is reimported.
-rw-r--r--editor/editor_node.cpp31
-rw-r--r--editor/editor_node.h4
2 files changed, 35 insertions, 0 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index cf1c1016fa..08c9b17718 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -3984,6 +3984,15 @@ HashMap<StringName, Variant> EditorNode::get_modified_properties_for_node(Node *
return modified_property_map;
}
+void EditorNode::update_ownership_table_for_addition_node_ancestors(Node *p_current_node, HashMap<Node *, Node *> &p_ownership_table) {
+ p_ownership_table.insert(p_current_node, p_current_node->get_owner());
+
+ for (int i = 0; i < p_current_node->get_child_count(); i++) {
+ Node *child = p_current_node->get_child(i);
+ update_ownership_table_for_addition_node_ancestors(child, p_ownership_table);
+ }
+}
+
void EditorNode::update_diff_data_for_node(
Node *p_edited_scene,
Node *p_root,
@@ -4079,6 +4088,16 @@ void EditorNode::update_diff_data_for_node(
if (node_3d) {
new_additive_node_entry.transform_3d = node_3d->get_relative_transform(node_3d->get_parent());
}
+
+ // Gathers the ownership of all ancestor nodes for later use.
+ HashMap<Node *, Node *> ownership_table;
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+ Node *child = p_node->get_child(i);
+ update_ownership_table_for_addition_node_ancestors(child, ownership_table);
+ }
+
+ new_additive_node_entry.ownership_table = ownership_table;
+
p_addition_list.push_back(new_additive_node_entry);
return;
@@ -6203,6 +6222,18 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
node_3d->set_transform(additive_node_entry.transform_3d);
}
}
+
+ // Restore the ownership of its ancestors
+ for (KeyValue<Node *, Node *> &E : additive_node_entry.ownership_table) {
+ Node *current_ancestor = E.key;
+ Node *ancestor_owner = E.value;
+
+ if (ancestor_owner == original_node) {
+ ancestor_owner = instantiated_node;
+ }
+
+ current_ancestor->set_owner(ancestor_owner);
+ }
}
// Restore the selection.
diff --git a/editor/editor_node.h b/editor/editor_node.h
index eefe45ca1f..8ad5969249 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -832,6 +832,8 @@ public:
// Used if the original parent node is lost
Transform2D transform_2d;
Transform3D transform_3d;
+ // Used to keep track of the ownership of all ancestor nodes so they can be restored later.
+ HashMap<Node *, Node *> ownership_table;
};
struct ConnectionWithNodePath {
@@ -846,6 +848,8 @@ public:
List<Node::GroupInfo> groups;
};
+ void update_ownership_table_for_addition_node_ancestors(Node *p_current_node, HashMap<Node *, Node *> &p_ownership_table);
+
void update_diff_data_for_node(
Node *p_edited_scene,
Node *p_root,