@@ -1042,11 +1042,17 @@ void EditorNode::_resources_reimporting(const Vector<String> &p_resources) {
10421042 // because if a mesh is present in an inherited scene, the resource will be modified in
10431043 // the inherited scene. Then, get_modified_properties_for_node will return the mesh property,
10441044 // which will trigger a recopy of the previous mesh, preventing the reload.
1045+ scenes_modification_table.clear ();
1046+ List<String> scenes;
10451047 for (const String &res_path : p_resources) {
10461048 if (ResourceLoader::get_resource_type (res_path) == " PackedScene" ) {
1047- preload_reimporting_with_path_in_edited_scenes (res_path);
1049+ scenes. push_back (res_path);
10481050 }
10491051 }
1052+
1053+ if (scenes.size () > 0 ) {
1054+ preload_reimporting_with_path_in_edited_scenes (scenes);
1055+ }
10501056}
10511057
10521058void EditorNode::_resources_reimported (const Vector<String> &p_resources) {
@@ -1080,9 +1086,10 @@ void EditorNode::_resources_reimported(const Vector<String> &p_resources) {
10801086
10811087 for (const String &E : scenes) {
10821088 reload_scene (E);
1083- reload_instances_with_path_in_edited_scenes (E);
10841089 }
10851090
1091+ reload_instances_with_path_in_edited_scenes ();
1092+
10861093 _set_current_scene_nocheck (current_tab);
10871094}
10881095
@@ -5870,9 +5877,7 @@ void EditorNode::find_all_instances_inheriting_path_in_node(Node *p_root, Node *
58705877 }
58715878}
58725879
5873- void EditorNode::preload_reimporting_with_path_in_edited_scenes (const String &p_instance_path) {
5874- scenes_modification_table.clear ();
5875-
5880+ void EditorNode::preload_reimporting_with_path_in_edited_scenes (const List<String> &p_scenes) {
58765881 EditorProgress progress (" preload_reimporting_scene" , TTR (" Preparing scenes for reload" ), editor_data.get_edited_scene_count ());
58775882
58785883 int original_edited_scene_idx = editor_data.get_edited_scene ();
@@ -5882,35 +5887,42 @@ void EditorNode::preload_reimporting_with_path_in_edited_scenes(const String &p_
58825887 for (int current_scene_idx = 0 ; current_scene_idx < editor_data.get_edited_scene_count (); current_scene_idx++) {
58835888 progress.step (vformat (TTR (" Analyzing scene %s" ), editor_data.get_scene_title (current_scene_idx)), current_scene_idx);
58845889
5885- if (editor_data.get_scene_path (current_scene_idx) == p_instance_path) {
5886- continue ;
5887- }
58885890 Node *edited_scene_root = editor_data.get_edited_scene_root (current_scene_idx);
58895891
58905892 if (edited_scene_root) {
5891- List<Node *> instance_list;
5892- find_all_instances_inheriting_path_in_node (edited_scene_root, edited_scene_root, p_instance_path, instance_list);
5893- if (instance_list.size () > 0 ) {
5894- SceneModificationsEntry scene_motifications;
5895- editor_data.set_edited_scene (current_scene_idx);
5893+ SceneModificationsEntry scene_motifications;
58965894
5897- List<Node *> instance_list_with_children;
5898- for (Node *original_node : instance_list) {
5899- InstanceModificationsEntry instance_modifications;
5895+ for (const String &instance_path : p_scenes) {
5896+ if (editor_data.get_scene_path (current_scene_idx) == instance_path) {
5897+ continue ;
5898+ }
59005899
5901- // Fetching all the modified properties of the nodes reimported scene.
5902- get_preload_scene_modification_table (edited_scene_root, original_node, original_node, instance_modifications);
5900+ List<Node *> instance_list;
5901+ find_all_instances_inheriting_path_in_node (edited_scene_root, edited_scene_root, instance_path, instance_list);
5902+ if (instance_list.size () > 0 ) {
5903+ editor_data.set_edited_scene (current_scene_idx);
59035904
5904- instance_modifications.original_node = original_node;
5905- scene_motifications.instance_list .push_back (instance_modifications);
5905+ List<Node *> instance_list_with_children;
5906+ for (Node *original_node : instance_list) {
5907+ InstanceModificationsEntry instance_modifications;
59065908
5907- instance_list_with_children.push_back (original_node);
5908- get_children_nodes (original_node, instance_list_with_children);
5909- }
5909+ // Fetching all the modified properties of the nodes reimported scene.
5910+ get_preload_scene_modification_table (edited_scene_root, original_node, original_node, instance_modifications);
5911+
5912+ instance_modifications.original_node = original_node;
5913+ instance_modifications.instance_path = instance_path;
5914+ scene_motifications.instance_list .push_back (instance_modifications);
59105915
5911- // Search the scene to find nodes that references the nodes will be recreated.
5912- get_preload_modifications_reference_to_nodes (edited_scene_root, edited_scene_root, instance_list, instance_list_with_children, scene_motifications.other_instances_modifications );
5916+ instance_list_with_children.push_back (original_node);
5917+ get_children_nodes (original_node, instance_list_with_children);
5918+ }
5919+
5920+ // Search the scene to find nodes that references the nodes will be recreated.
5921+ get_preload_modifications_reference_to_nodes (edited_scene_root, edited_scene_root, instance_list, instance_list_with_children, scene_motifications.other_instances_modifications );
5922+ }
5923+ }
59135924
5925+ if (scene_motifications.instance_list .size () > 0 ) {
59145926 scenes_modification_table[current_scene_idx] = scene_motifications;
59155927 }
59165928 }
@@ -5921,24 +5933,30 @@ void EditorNode::preload_reimporting_with_path_in_edited_scenes(const String &p_
59215933 progress.step (TTR (" Preparation done." ), editor_data.get_edited_scene_count ());
59225934}
59235935
5924- void EditorNode::reload_instances_with_path_in_edited_scenes (const String &p_instance_path ) {
5936+ void EditorNode::reload_instances_with_path_in_edited_scenes () {
59255937 if (scenes_modification_table.size () == 0 ) {
59265938 return ;
59275939 }
5928- Array replaced_nodes;
5929-
59305940 EditorProgress progress (" reloading_scene" , TTR (" Scenes reloading" ), editor_data.get_edited_scene_count ());
59315941 progress.step (TTR (" Reloading..." ), 0 , true );
59325942
5933- // Reload the new instance.
59345943 Error err;
5935- Ref<PackedScene> instance_scene_packed_scene = ResourceLoader::load (p_instance_path, " " , ResourceFormatLoader::CACHE_MODE_REPLACE, &err);
5944+ Array replaced_nodes;
5945+ HashMap<String, Ref<PackedScene>> local_scene_cache;
5946+
5947+ // Reload the new instances.
5948+ for (KeyValue<int , SceneModificationsEntry> &scene_modifications_elem : scenes_modification_table) {
5949+ for (InstanceModificationsEntry instance_modifications : scene_modifications_elem.value .instance_list ) {
5950+ if (!local_scene_cache.has (instance_modifications.instance_path )) {
5951+ Ref<PackedScene> instance_scene_packed_scene = ResourceLoader::load (instance_modifications.instance_path , " " , ResourceFormatLoader::CACHE_MODE_REPLACE, &err);
59365952
5937- ERR_FAIL_COND (err != OK);
5938- ERR_FAIL_COND (instance_scene_packed_scene.is_null ());
5953+ ERR_FAIL_COND (err != OK);
5954+ ERR_FAIL_COND (instance_scene_packed_scene.is_null ());
59395955
5940- HashMap<String, Ref<PackedScene>> local_scene_cache;
5941- local_scene_cache[p_instance_path] = instance_scene_packed_scene;
5956+ local_scene_cache[instance_modifications.instance_path ] = instance_scene_packed_scene;
5957+ }
5958+ }
5959+ }
59425960
59435961 // Save the current scene state/selection in case of lost.
59445962 Dictionary editor_state = _get_main_scene_state ();
@@ -5980,11 +5998,12 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
59805998 for (InstanceModificationsEntry instance_modifications : scene_modifications->instance_list ) {
59815999 Node *original_node = instance_modifications.original_node ;
59826000 String original_node_file_path = original_node->get_scene_file_path ();
6001+ Ref<PackedScene> instance_scene_packed_scene = local_scene_cache[instance_modifications.instance_path ];
59836002
59846003 // Load a replacement scene for the node.
59856004 Ref<PackedScene> current_packed_scene;
59866005 Ref<PackedScene> base_packed_scene;
5987- if (original_node_file_path == p_instance_path ) {
6006+ if (original_node_file_path == instance_modifications. instance_path ) {
59886007 // If the node file name directly matches the scene we're replacing,
59896008 // just load it since we already cached it.
59906009 current_packed_scene = instance_scene_packed_scene;
@@ -6033,7 +6052,7 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
60336052 // it's a muli-level inheritance scene. We should use
60346053 NodePath scene_path_to_node = current_edited_scene->get_path_to (original_node);
60356054 Ref<SceneState> scene_state = current_edited_scene->get_scene_inherited_state ();
6036- if (scene_path_to_node != " ." && scene_state.is_valid () && scene_state->get_path () != p_instance_path && scene_state->find_node_by_path (scene_path_to_node) >= 0 ) {
6055+ if (scene_path_to_node != " ." && scene_state.is_valid () && scene_state->get_path () != instance_modifications. instance_path && scene_state->find_node_by_path (scene_path_to_node) >= 0 ) {
60376056 Node *root_node = scene_state->instantiate (SceneState::GenEditState::GEN_EDIT_STATE_INSTANCE);
60386057 instantiated_node = root_node->get_node (scene_path_to_node);
60396058
@@ -6167,7 +6186,7 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
61676186 if (owner) {
61686187 Ref<SceneState> ss_inst = owner->get_scene_instance_state ();
61696188 if (ss_inst.is_valid ()) {
6170- ss_inst->update_instance_resource (p_instance_path , current_packed_scene);
6189+ ss_inst->update_instance_resource (instance_modifications. instance_path , current_packed_scene);
61716190 }
61726191
61736192 owner->set_editable_instance (instantiated_node, is_editable);
0 commit comments