From 225a5e225f83296144bc5d4351da9178c61e8fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=9D=92=E5=B1=B1?= Date: Fri, 13 Oct 2023 16:38:33 +0800 Subject: [PATCH] Fix saving wrong edited scene state when switching scene tabs When creating a new scene, the scene tab will actually switch to the newly created one. Also worth noting that switching scene tabs saves state (by `save_edited_scene_state`). When trying New Scene again, the previously empty scene tab will be removed. So the correct logic is: switch the tab save state first, and then remove the previous empty scene tab. To prevent `current_edited_scene` from being incorrect when saving state. --- editor/editor_node.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 665e609cb06..36dba397cd9 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3664,6 +3664,8 @@ void EditorNode::fix_dependencies(const String &p_for_file) { int EditorNode::new_scene() { int idx = editor_data.add_edited_scene(-1); + _set_current_scene(idx); // Before trying to remove an empty scene, set the current tab index to the newly added tab index. + // Remove placeholder empty scene. if (editor_data.get_edited_scene_count() > 1) { for (int i = 0; i < editor_data.get_edited_scene_count() - 1; i++) { @@ -3674,9 +3676,7 @@ int EditorNode::new_scene() { } } } - idx = MAX(idx, 0); - _set_current_scene(idx); editor_data.clear_editor_states(); scene_tabs->update_scene_tabs(); return idx; @@ -3834,6 +3834,12 @@ Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, b // If we are, we'll edit it after the restoration is done. if (!restoring_scenes) { push_item(new_scene); + } else { + // Initialize history for restored scenes. + ObjectID id = new_scene->get_instance_id(); + if (id != editor_history.get_current()) { + editor_history.add_object(id); + } } // Load the selected nodes.