Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix uninstanced scenes not reloading on reimport

Tomás Civiero92e3a06d0bd3
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index f1909c96898..8348b81bbb2 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -1504,6 +1504,7 @@ void EditorNode::_resources_reimporting(const Vector<String> &p_resources) {
scenes_modification_table.clear();
scenes_reimported.clear();
resources_reimported.clear();
+ uninstanced_scenes_reimported.clear();
EditorFileSystem *editor_file_system = EditorFileSystem::get_singleton();
for (const String &res_path : p_resources) {
// It's faster to use EditorFileSystem::get_file_type than fetching the resource type from disk.
@@ -1559,6 +1560,7 @@ void EditorNode::_resources_reimported(const Vector<String> &p_resources) {
}
reload_instances_with_path_in_edited_scenes();
+ reload_uninstanced_scenes();
scenes_modification_table.clear();
scenes_reimported.clear();
@@ -7405,6 +7407,8 @@ void EditorNode::preload_reimporting_with_path_in_edited_scenes(const List<Strin
// Search the scene to find nodes that references the nodes will be recreated.
get_preload_modifications_reference_to_nodes(edited_scene_root, edited_scene_root, instances_to_reimport, instance_list_with_children, scene_modifications.other_instances_modifications);
+ } else {
+ uninstanced_scenes_reimported.push_back(instance_path);
}
}
@@ -7791,6 +7795,20 @@ void EditorNode::reload_instances_with_path_in_edited_scenes() {
progress.step(TTR("Reloading done."), editor_data.get_edited_scene_count());
}
+void EditorNode::reload_uninstanced_scenes() {
+ if (uninstanced_scenes_reimported.is_empty()) {
+ return;
+ }
+ // Reloads resources stored in memory (cached in undo history for example).
+ for (String &scene_path : uninstanced_scenes_reimported) {
+ Error err;
+ Ref<PackedScene> instance_scene_packed_scene = ResourceLoader::load(scene_path, "", ResourceFormatLoader::CACHE_MODE_REPLACE, &err);
+
+ ERR_FAIL_COND(err != OK);
+ ERR_FAIL_COND(instance_scene_packed_scene.is_null());
+ }
+}
+
void EditorNode::_remove_all_not_owned_children(Node *p_node, Node *p_owner) {
Vector<Node *> nodes_to_remove;
if (p_node != p_owner && p_node->get_owner() != p_owner) {
diff --git a/editor/editor_node.h b/editor/editor_node.h
index e6cd06b9540..8fa0d6b401e 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -947,6 +947,7 @@ public:
HashMap<int, SceneModificationsEntry> scenes_modification_table;
List<String> scenes_reimported;
List<String> resources_reimported;
+ List<String> uninstanced_scenes_reimported;
void update_node_from_node_modification_entry(Node *p_node, ModificationNodeEntry &p_node_modification);
@@ -1027,6 +1028,7 @@ public:
void find_all_instances_inheriting_path_in_node(Node *p_root, Node *p_node, const String &p_instance_path, HashSet<Node *> &p_instance_list);
void preload_reimporting_with_path_in_edited_scenes(const List<String> &p_scenes);
void reload_instances_with_path_in_edited_scenes();
+ void reload_uninstanced_scenes();
bool is_exiting() const { return exiting; }