From cebde9b848fa6bf544110ebe2d534c4ab3678513 Mon Sep 17 00:00:00 2001 From: Jonathan Jay <163188305+Jonathan-Jay-TB@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:10:44 -0400 Subject: [PATCH 1/2] Added checks for scene type reimports -Mainly affects gltf and other custom importable files -Removes duplicate that is created -Adds safeties to certain parts of the EditorNode script --- editor/editor_node.cpp | 32 ++++++++++++++++++++++++++++++-- editor/gui/scene_tree_editor.cpp | 3 ++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 89e5e3f3b073..10e8ba47f467 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1053,6 +1053,16 @@ void EditorNode::_resources_reimported(const Vector &p_resources) { } scene_tabs->set_current_tab(current_tab); + + // Means there might've been a clone that got added. + // They are removed in reload_instances_with_path_in_edited_scenes + // so now we fix the scene tree + if (!scenes.is_empty()) { + Node *current = editor_data.get_edited_scene_root(); + if (current) { + set_edited_scene(current); + } + } } void EditorNode::_sources_changed(bool p_exist) { @@ -3674,7 +3684,9 @@ void EditorNode::set_edited_scene(Node *p_scene) { if (old_edited_scene_root->get_parent() == scene_root) { scene_root->remove_child(old_edited_scene_root); } - old_edited_scene_root->disconnect(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene)); + if (old_edited_scene_root->is_connected(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene))) { + old_edited_scene_root->disconnect(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene)); + } } get_editor_data().set_edited_scene_root(p_scene); @@ -3687,7 +3699,7 @@ void EditorNode::set_edited_scene(Node *p_scene) { } if (p_scene) { - if (p_scene->get_parent() != scene_root) { + if (p_scene->get_parent() == nullptr && p_scene->get_parent() != scene_root) { scene_root->add_child(p_scene, true); } p_scene->connect(SNAME("replacing_by"), callable_mp(this, &EditorNode::set_edited_scene)); @@ -5586,6 +5598,7 @@ void EditorNode::find_all_instances_inheriting_path_in_node(Node *p_root, Node * void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_instance_path) { int original_edited_scene_idx = editor_data.get_edited_scene(); HashMap> edited_scene_map; + List inherited_scenes; // Walk through each opened scene to get a global list of all instances which match // the current reimported scenes. @@ -5599,6 +5612,11 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins if (valid_nodes.size() > 0) { edited_scene_map[i] = valid_nodes; } + + Ref inherited_state = edited_scene_root->get_scene_inherited_state(); + if (inherited_state.is_valid() && inherited_state->get_path() == p_instance_path) { + inherited_scenes.push_back(i); + } } } } @@ -5909,6 +5927,16 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins } edited_scene_map.clear(); } + + // Remove the node from viewport since we're still in the reloading process + if (!inherited_scenes.is_empty()) { + for (int scene : inherited_scenes) { + Node *original_scene = editor_data.get_edited_scene_root(scene); + if (original_scene->get_parent() == scene_root) + scene_root->remove_child(original_scene); + } + } + editor_data.set_edited_scene(original_edited_scene_idx); _edit_current(); diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 248678662ca8..b2bad18ac32a 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -196,7 +196,8 @@ void SceneTreeEditor::_toggle_visible(Node *p_node) { } void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { - if (!p_node) { + // If the node is null or outside of the tree, don't do this stuff? + if (!p_node || !p_node->is_inside_tree()) { return; } From f85cedd7978ffe4978bdda81e48135dbfeacda12 Mon Sep 17 00:00:00 2001 From: Jonathan Jay <56273460+Jonathan-Jay@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:17:57 -0400 Subject: [PATCH 2/2] Changed variable to avoid shadowing --- editor/editor_node.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 10e8ba47f467..d322fe8e6df2 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1058,9 +1058,9 @@ void EditorNode::_resources_reimported(const Vector &p_resources) { // They are removed in reload_instances_with_path_in_edited_scenes // so now we fix the scene tree if (!scenes.is_empty()) { - Node *current = editor_data.get_edited_scene_root(); - if (current) { - set_edited_scene(current); + Node *current_edited_root = editor_data.get_edited_scene_root(); + if (current_edited_root) { + set_edited_scene(current_edited_root); } } }