From 0559fc58d17c82983bfa6d37207642178932ebde Mon Sep 17 00:00:00 2001 From: Oliver Dick Date: Sun, 28 Feb 2021 17:19:01 +0100 Subject: SceneTreeDock: Changed "Save Branch as Scene" to make use of Node::duplicate_from_editor, which is also used by "Duplicate" function of the SceneTreeDock - Removed Node::duplicate_and_reown method as it is not used anymore --- editor/scene_tree_dock.cpp | 20 +++++++++++++++++--- editor/scene_tree_dock.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'editor') diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 58589467a8..0975decefb 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -2321,10 +2321,14 @@ void SceneTreeDock::_new_scene_from(String p_file) { Node *base = selection.front()->get(); - Map reown; - reown[editor_data->get_edited_scene_root()] = base; - Node *copy = base->duplicate_and_reown(reown); + Map duplimap; + Node *copy = base->duplicate_from_editor(duplimap); + if (copy) { + for (int i = 0; i < copy->get_child_count(); i++) { + _set_node_owner_recursive(copy->get_child(i), copy); + } + Ref sdata = memnew(PackedScene); Error err = sdata->pack(copy); memdelete(copy); @@ -2354,6 +2358,16 @@ 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); + } + + for (int i = 0; i < p_node->get_child_count(); i++) { + _set_node_owner_recursive(p_node->get_child(i), p_owner); + } +} + static bool _is_node_visible(Node *p_node) { if (!p_node->get_owner()) { return false; diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index 3779b61c60..807e922418 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -203,6 +203,7 @@ class SceneTreeDock : public VBoxContainer { void _import_subscene(); void _new_scene_from(String p_file); + void _set_node_owner_recursive(Node *p_node, Node *p_owner); bool _validate_no_foreign(); bool _validate_no_instance(); -- cgit v1.2.3