@@ -4446,6 +4446,21 @@ void EditorNode::update_reimported_diff_data_for_additional_nodes(
44464446 }
44474447}
44484448
4449+ void EditorNode::replace_history_reimported_nodes (Node *p_original_root_node, Node *p_new_root_node, Node *p_node) {
4450+ NodePath scene_path_to_node = p_original_root_node->get_path_to (p_node);
4451+ Node *new_node = p_new_root_node->get_node_or_null (scene_path_to_node);
4452+ if (new_node) {
4453+ editor_history.replace_object (p_node->get_instance_id (), new_node->get_instance_id ());
4454+ } else {
4455+ editor_history.replace_object (p_node->get_instance_id (), ObjectID ());
4456+ }
4457+
4458+ for (int i = 0 ; i < p_node->get_child_count (); i++) {
4459+ Node *child = p_node->get_child (i);
4460+ replace_history_reimported_nodes (p_original_root_node, p_new_root_node, child);
4461+ }
4462+ }
4463+
44494464void EditorNode::open_request (const String &p_path) {
44504465 if (!opening_prev) {
44514466 List<String>::Element *prev_scene_item = previous_scenes.find (p_path);
@@ -6094,6 +6109,13 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
60946109 owned_node->set_owner (nullptr );
60956110 }
60966111
6112+ // Replace the old nodes in the history with the new ones.
6113+ // Otherwise, the history will contain old nodes, and some could still be
6114+ // instantiated if used elsewhere, causing the "current edited item" to be
6115+ // linked to a node that will be destroyed later. This caused the editor to
6116+ // crash when reimporting scenes with animations when "Editable children" was enabled.
6117+ replace_history_reimported_nodes (original_node, instantiated_node, original_node);
6118+
60976119 // Delete all the remaining node children.
60986120 while (original_node->get_child_count ()) {
60996121 Node *child = original_node->get_child (0 );
0 commit comments