Skip to content

Commit

Permalink
Merge pull request #91 from johanhelsing/fix-restore-entity-desync
Browse files Browse the repository at this point in the history
Fix desync when restoring entities
  • Loading branch information
gschup authored Nov 9, 2023
2 parents b6b952a + 684e6d3 commit f1593f9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/snapshot/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ impl EntitySnapshotPlugin {
rollback_mapping.entry(rollback).or_insert((None, None)).0 = Some(current_entity);
}

for (current_entity, old_entity) in rollback_mapping.values() {
for (rollback, (current_entity, old_entity)) in rollback_mapping {
match (current_entity, old_entity) {
(Some(current_entity), Some(old_entity)) => {
entity_map.insert(*current_entity, *old_entity);
entity_map.insert(current_entity, old_entity);
}
(Some(current_entity), None) => {
commands.entity(*current_entity).despawn();
commands.entity(current_entity).despawn();
}
(None, Some(old_entity)) => {
let current_entity = commands.spawn_empty().id();
entity_map.insert(*old_entity, current_entity);
let current_entity = commands.spawn(rollback).id();
entity_map.insert(old_entity, current_entity);
}
(None, None) => unreachable!(
"Rollback keys could only be added if they had an old or current Entity"
Expand Down

0 comments on commit f1593f9

Please sign in to comment.