Skip to content

Commit

Permalink
Merge pull request #83597 from SaracenOne/duplicate_foreign_nodes
Browse files Browse the repository at this point in the history
Support duplication of foreign nodes.
  • Loading branch information
akien-mga committed Oct 25, 2023
2 parents 9798ae3 + 9d6f570 commit cd46add
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
break;
}

if (!_validate_no_foreign()) {
break;
}

List<Node *> selection = editor_selection->get_selected_node_list();
if (selection.size() == 0) {
break;
Expand All @@ -704,7 +700,15 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
Node *parent = node->get_parent();

List<Node *> owned;
node->get_owned_by(node->get_owner(), &owned);
Node *owner = node;
while (owner) {
List<Node *> cur_owned;
node->get_owned_by(owner, &cur_owned);
owner = owner->get_owner();
for (Node *F : cur_owned) {
owned.push_back(F);
}
}

HashMap<const Node *, Node *> duplimap;
Node *dup = node->duplicate_from_editor(duplimap);
Expand All @@ -724,9 +728,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);

Expand Down

0 comments on commit cd46add

Please sign in to comment.