From 7ee4ed46472c1df5899eaf5003b070f76daa5b90 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 20 Oct 2022 15:06:17 +0800 Subject: [PATCH] Fix wrong owner for editor plugin created nodes in instanced scene --- editor/plugins/mesh_instance_editor_plugin.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/editor/plugins/mesh_instance_editor_plugin.cpp b/editor/plugins/mesh_instance_editor_plugin.cpp index 79798bc96..42a8edf14 100644 --- a/editor/plugins/mesh_instance_editor_plugin.cpp +++ b/editor/plugins/mesh_instance_editor_plugin.cpp @@ -102,7 +102,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { StaticBody *body = memnew(StaticBody); body->add_child(cshape); - Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner(); + Node *owner = get_tree()->get_edited_scene_root(); ur->create_action(TTR("Create Static Trimesh Body")); ur->add_do_method(node, "add_child", body); @@ -137,7 +137,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { StaticBody *body = memnew(StaticBody); body->add_child(cshape); - Node *owner = instance == get_tree()->get_edited_scene_root() ? instance : instance->get_owner(); + Node *owner = get_tree()->get_edited_scene_root(); ur->add_do_method(instance, "add_child", body); ur->add_do_method(body, "set_owner", owner); @@ -166,7 +166,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { cshape->set_shape(shape); cshape->set_transform(node->get_transform()); - Node *owner = node->get_owner(); + Node *owner = get_tree()->get_edited_scene_root(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); @@ -209,7 +209,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { cshape->set_shape(shape); cshape->set_transform(node->get_transform()); - Node *owner = node->get_owner(); + Node *owner = get_tree()->get_edited_scene_root(); ur->add_do_method(node->get_parent(), "add_child", cshape); ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1); @@ -244,7 +244,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { cshape->set_shape(shapes[i]); cshape->set_transform(node->get_transform()); - Node *owner = node->get_owner(); + Node *owner = get_tree()->get_edited_scene_root(); ur->add_do_method(node->get_parent(), "add_child", cshape); ur->add_do_method(node->get_parent(), "move_child", cshape, node->get_index() + 1); @@ -267,7 +267,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { NavigationMeshInstance *nmi = memnew(NavigationMeshInstance); nmi->set_navigation_mesh(nmesh); - Node *owner = node == get_tree()->get_edited_scene_root() ? node : node->get_owner(); + Node *owner = get_tree()->get_edited_scene_root(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action(TTR("Create Navigation Mesh")); @@ -429,10 +429,7 @@ void MeshInstanceEditor::_create_outline_mesh() { MeshInstance *mi = memnew(MeshInstance); mi->set_mesh(mesho); - Node *owner = node->get_owner(); - if (get_tree()->get_edited_scene_root() == node) { - owner = node; - } + Node *owner = get_tree()->get_edited_scene_root(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();