From f8463df11a1f070fd8d355da7ab0964a55084eb7 Mon Sep 17 00:00:00 2001 From: Marcus Brummer Date: Sun, 7 Jun 2020 19:18:37 +0200 Subject: [PATCH] Re-apply basis of newly added node (via drag-n-drop) in editor viewport --- editor/plugins/spatial_editor_plugin.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 0219f631fb3..59fe641c56c 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -3641,14 +3641,19 @@ bool SpatialEditorViewport::_create_instance(Node *parent, String &path, const P editor_data->get_undo_redo().add_do_method(sed, "live_debug_instance_node", editor->get_edited_scene()->get_path_to(parent), path, new_name); editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); - Transform global_transform; - Spatial *parent_spatial = Object::cast_to(parent); - if (parent_spatial) - global_transform = parent_spatial->get_global_gizmo_transform(); + Spatial *spatial = Object::cast_to(instanced_scene); + if (spatial) { + Transform global_transform; + Spatial *parent_spatial = Object::cast_to(parent); + if (parent_spatial) { + global_transform = parent_spatial->get_global_gizmo_transform(); + } - global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); + global_transform.origin = spatial_editor->snap_point(_get_instance_position(p_point)); + global_transform.basis *= spatial->get_transform().basis; - editor_data->get_undo_redo().add_do_method(instanced_scene, "set_global_transform", global_transform); + editor_data->get_undo_redo().add_do_method(instanced_scene, "set_global_transform", global_transform); + } return true; }