From 7f96f0603e16a970c7b0ea1fba936e56baf80d4a Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 13 Dec 2015 20:39:01 -0300 Subject: -scenes are properly reloaded when a dependency changes, fixes #2896 (it's clevery done so local changes to scenes are kept even if unsaved) --- tools/editor/editor_node.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tools/editor/editor_node.cpp') diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 3dbca760f0..05df0a3e48 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -955,7 +955,23 @@ void EditorNode::_save_scene(String p_file) { _set_scene_metadata(); - Ref sdata = memnew( PackedScene ); + + + Ref sdata; + + if (ResourceCache::has(p_file)) { + // something may be referencing this resource and we are good with that. + // we must update it, but also let the previous scene state go, as + // old version still work for referencing changes in instanced or inherited scenes + + sdata = Ref( ResourceCache::get(p_file)->cast_to() ); + if (sdata.is_valid()) + sdata->recreate_state(); + else + sdata.instance(); + } else { + sdata.instance(); + } Error err = sdata->pack(scene); @@ -3414,8 +3430,18 @@ void EditorNode::set_current_version(uint64_t p_version) { bool EditorNode::is_changing_scene() const { return changing_scene; } + +void EditorNode::_clear_undo_history() { + + get_undo_redo()->clear_history(); +} + void EditorNode::set_current_scene(int p_idx) { + if (editor_data.check_and_update_scene(p_idx)) { + call_deferred("_clear_undo_history"); + } + changing_scene=true; editor_data.save_edited_scene_state(editor_selection,&editor_history,_get_main_scene_state()); @@ -4113,6 +4139,7 @@ void EditorNode::_bind_methods() { ObjectTypeDB::bind_method("_toggle_search_bar",&EditorNode::_toggle_search_bar); ObjectTypeDB::bind_method("_clear_search_box",&EditorNode::_clear_search_box); + ObjectTypeDB::bind_method("_clear_undo_history",&EditorNode::_clear_undo_history); ObjectTypeDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin); ObjectTypeDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin); -- cgit v1.2.3