How entity identity and reconciliation work
mainBecause Bevy Entity IDs are not stable across despawn/respawn cycles, bevy_ggrs uses specific components to maintain logical identity during rollbacks:
Rollback: A marker component. Add this to any entity that must be saved and rolled back. Adding this automatically assigns aRollbackId.RollbackId: An immutable component representing theEntityID at the timeRollbackwas first added. This is the stable key used inGgrsComponentSnapshot.RollbackOrdered: A resource maintaining a stable, insertion-ordered list of allRollbackIds, used for deterministic checksums.
Reconciliation Process:
During LoadWorld, the EntitySnapshotPlugin compares the live entity set against the snapshot:
- Exists in both: Maps
current → snapshotIDs. - In snapshot only: Spawns a new entity with the same
Rollback+RollbackIdand mapsnew_id → old_id. - In world only: Despawns the entity.
Mappings are stored in RollbackEntityMap and used by LoadWorldSystems::Mapping to fix up stale Entity references in components or resources.