From 9d6f570c28801e998da34f7e1ced6751e1283628 Mon Sep 17 00:00:00 2001 From: Saracen Date: Wed, 18 Oct 2023 16:52:30 +0100 Subject: [PATCH] Support duplication of foreign nodes. --- editor/scene_tree_dock.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index d1e2ba0fe097..13927177d8de 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -680,10 +680,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { break; } - if (!_validate_no_foreign()) { - break; - } - List selection = editor_selection->get_selected_node_list(); if (selection.size() == 0) { break; @@ -703,7 +699,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { Node *parent = node->get_parent(); List owned; - node->get_owned_by(node->get_owner(), &owned); + Node *owner = node; + while (owner) { + List cur_owned; + node->get_owned_by(owner, &cur_owned); + owner = owner->get_owner(); + for (Node *F : cur_owned) { + owned.push_back(F); + } + } HashMap duplimap; Node *dup = node->duplicate_from_editor(duplimap); @@ -723,9 +727,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { continue; } Node *d = duplimap[F]; - undo_redo->add_do_method(d, "set_owner", node->get_owner()); + undo_redo->add_do_method(d, "set_owner", edited_scene); } undo_redo->add_do_method(editor_selection, "add_node", dup); + undo_redo->add_do_method(dup, "set_owner", edited_scene); undo_redo->add_undo_method(parent, "remove_child", dup); undo_redo->add_do_reference(dup);