diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 3d0dc2bb9..b406c5766 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7957,7 +7957,7 @@ impl Game<'_> { if wait { self.save.flush(); } - self.save_entities()?; + self.save_entities(wait)?; self.save_maps(); self.save_random_sequences(); self.save_raids(); diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rs index d7bb6d558..054f2c2fc 100644 --- a/crates/horizon-client/src/game/persist.rs +++ b/crates/horizon-client/src/game/persist.rs @@ -830,7 +830,10 @@ impl Game<'_> { out.into_iter().collect() } /// Write the entities of every resident chunk (an autosave or quit). - pub(super) fn save_entities(&mut self) -> Result<()> { + /// Without `wait` (the autosave) they are written on the region writer + /// meanwhile: `PersistentEntitySectionManager.autoSave` stores them + /// without `saveAll`'s flush. + pub(super) fn save_entities(&mut self, wait: bool) -> Result<()> { self.spawn_loaded_entities(); let keys: HashSet<(i32, i32)> = self.world.chunks.keys().copied().collect(); let chunks = self.entity_chunks(&keys, false); @@ -849,7 +852,11 @@ impl Game<'_> { .collect(); self.persist.uuids.retain(|id, _| alive.contains(id)); self.persist.raw.retain(|id, _| alive.contains(id)); - self.save.save_entities(chunks) + if wait { + self.save.save_entities(chunks) + } else { + self.save.save_entities_later(chunks) + } } /// Save and remove the entities of chunks that unloaded. pub(super) fn unload_entities(&mut self, unloaded: &[Arc]) {