From 95248a7d722d9b2fd9ce83f665386c9b4744a692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Thu, 7 Sep 2023 20:34:18 +0800 Subject: [PATCH] Fix bugs of copying scene root node or pasting node as scene root Fix crash when pasting a node as a new scene root. Fix owner was not set correctly when copying scene root node from unsaved scene. The owner of the root node is `nullptr`, which was ignored before. --- editor/scene_tree_dock.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 161598b50fa..6903f5160d3 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -493,7 +493,7 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { // Preserve ownership relations ready for pasting. List owned; - node->get_owned_by(node->get_owner(), &owned); + node->get_owned_by(node->get_owner() ? node->get_owner() : node, &owned); for (Node *F : owned) { if (!duplimap.has(F) || F == node) { @@ -3394,7 +3394,11 @@ List SceneTreeDock::paste_nodes(bool p_paste_as_sibling) { } EditorUndoRedoManager *ur = EditorUndoRedoManager::get_singleton(); - ur->create_action(vformat(p_paste_as_sibling ? TTR("Paste Node(s) as Sibling of %s") : TTR("Paste Node(s) as Child of %s"), paste_parent->get_name()), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene()); + if (paste_parent) { + ur->create_action(vformat(p_paste_as_sibling ? TTR("Paste Node(s) as Sibling of %s") : TTR("Paste Node(s) as Child of %s"), paste_parent->get_name()), UndoRedo::MERGE_DISABLE, edited_scene); + } else { + ur->create_action(TTR("Paste Node(s) as Root"), UndoRedo::MERGE_DISABLE, edited_scene); + } ur->add_do_method(editor_selection, "clear"); HashMap, Ref> resource_remap;