From 72134a7f2a4af1781208d6c46909d29caa5dbe19 Mon Sep 17 00:00:00 2001 From: hilfazer Date: Mon, 22 Feb 2021 16:50:44 +0100 Subject: [PATCH] Support for duplication of nested instanced scenes --- editor/scene_tree_dock.cpp | 10 ---------- scene/main/node.cpp | 12 ++++++++++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 58589467a83..3b48685264b 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -672,7 +672,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor_data->get_undo_redo().add_do_method(editor_selection, "clear"); Node *dupsingle = nullptr; - List editable_children; selection.sort_custom(); @@ -688,10 +687,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Map duplimap; Node *dup = node->duplicate_from_editor(duplimap); - if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node)) { - editable_children.push_back(dup); - } - ERR_CONTINUE(!dup); if (selection.size() == 1) { @@ -726,11 +721,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (dupsingle) { editor->push_item(dupsingle); } - - for (List::Element *E = editable_children.back(); E; E = E->prev()) { - _toggle_editable_children(E->get()); - } - } break; case TOOL_REPARENT: { if (!profile_allow_editing) { diff --git a/scene/main/node.cpp b/scene/main/node.cpp index df00af8f5ba..be3e3a5637b 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -2052,6 +2052,7 @@ Node *Node::_duplicate(int p_flags, Map *r_duplimap) const if (get_filename() != "") { //an instance node->set_filename(get_filename()); + node->data.editable_instance = data.editable_instance; } StringName script_property_name = CoreStringNames::get_singleton()->_script; @@ -2064,19 +2065,26 @@ Node *Node::_duplicate(int p_flags, Map *r_duplimap) const // Since nodes in the instanced hierarchy won't be duplicated explicitly, we need to make an inventory // of all the nodes in the tree of the instanced scene in order to transfer the values of the properties + Vector instance_roots; + instance_roots.push_back(this); + 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); // Skip nodes not really belonging to the instanced hierarchy; they'll be processed normally later // but remember non-instanced nodes that are hidden below instanced ones - if (descendant->data.owner != this) { - if (descendant->get_parent() && descendant->get_parent() != this && descendant->get_parent()->data.owner == this && descendant->data.owner != descendant->get_parent()) { + if (!instance_roots.has(descendant->get_owner())) { + if (descendant->get_parent() && descendant->get_parent() != this && descendant->data.owner != descendant->get_parent()) { hidden_roots.push_back(descendant); } continue; } node_tree.push_back(descendant); + + if (descendant->get_filename() != "" && instance_roots.has(descendant->get_owner())) { + instance_roots.push_back(descendant); + } } } }