{"id":15672732,"url":"https://github.com/johanhelsing/bevy_snap","last_synced_at":"2025-09-03T06:35:56.671Z","repository":{"id":77177907,"uuid":"443535193","full_name":"johanhelsing/bevy_snap","owner":"johanhelsing","description":"Saving and loading entity and resource state for bevy","archived":false,"fork":false,"pushed_at":"2023-03-03T23:06:20.000Z","size":33,"stargazers_count":17,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-06T21:49:52.735Z","etag":null,"topics":["bevy","bevy-engine","bevy-plugin","game-development","save"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/johanhelsing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-01T12:34:44.000Z","updated_at":"2024-07-03T03:47:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"77c33a33-e107-437e-8638-db8fb69f0613","html_url":"https://github.com/johanhelsing/bevy_snap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/johanhelsing/bevy_snap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johanhelsing%2Fbevy_snap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johanhelsing%2Fbevy_snap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johanhelsing%2Fbevy_snap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johanhelsing%2Fbevy_snap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/johanhelsing","download_url":"https://codeload.github.com/johanhelsing/bevy_snap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/johanhelsing%2Fbevy_snap/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273403937,"owners_count":25099299,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bevy","bevy-engine","bevy-plugin","game-development","save"],"created_at":"2024-10-03T15:30:49.352Z","updated_at":"2025-09-03T06:35:56.624Z","avatar_url":"https://github.com/johanhelsing.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## deprecation notice\n\nI'not currently working on this project or updating it to new versions of Bevy.\n\nMuch of the functionality is now covered by Bevy's built-in scene functionality.\n\nFor the things not covered by Bevy, there are other up-to-date community crates, like\n[bevy_save](https://github.com/hankjordan/bevy_save).\n\n# bevy_snap\n\nBevy snap is a crate for saving and loading snapshots of entity and resource\nstate.\n\nPotential usages:\n\n- Rewind game mechanic\n- Undo in turn-based games\n- Rollback in networked games\n\nAnd if serialization is implemented:\n\n- Save and load game state to disk\n- Sync game state across networked clients\n- Easily reproduce crashes by sending saves as diagnostics\n\n## Usage\n\n`bevy_snap` works by defining your own snapshot type. Register the types you\nwant to track by implementing the `SnapType` trait:\n\n```rust\nuse bevy_snap::*;\n\n#[derive(Default)]\nstruct MySnap;\n\nimpl SnapType for MySnap {\n    fn add_types(registry: \u0026mut TypeRegistry) {\n        // Register the types you want to be saved and loaded\n        registry.write().register::\u003cTransform\u003e();\n        registry.write().register::\u003cPlayer\u003e();\n\n        // Resources are also supported\n        registry.write().register::\u003cSteps\u003e();\n    }\n}\n```\n\nThe components that are to be tracked, need to implement the `Reflect` trait,\nand be marked as `Component`s:\n\n```rust\n#[derive(Component, Reflect, Default)]\n#[reflect(Component)]\nstruct Player;\n```\n\nAnd so do resources, but they need an additional `Resource` marker as well:\n\n```rust\n#[derive(Component, Reflect, Default)]\n#[reflect(Component, Resource)]\nstruct Score(i32);\n```\n\nWhen you start your app, add a `SnapPlugin` with your snap type as type\nparameter:\n\n```rust\n    .add_plugin(SnapPlugin::\u003cMySnap\u003e::default());\n```\n\nEntities that are to be tracked, need to have a unique `SnapshotId` component.\nYou could do this manually with `SnapshotId::new(some_int)`, but the simplest\nway is probably to use the `SnapshotIdProvider` resource that's automatically\nadded by the plugin:\n\n```rust\nfn startup(\n    mut commands: Commands, \n    mut snapshot_id_provider: ResMut\u003cSnapshotIdProvider\u003cMySnap\u003e\u003e\n) {\n    commands.spawn_bundle(PlayerBundle::default())\n        .insert(snapshot_id_provider.next());\n}\n```\n\nThen you can generate snapshot using the `.save()` command:\n\n```rust\nfn save_key(mut commands: Commands, keys: Res\u003cInput\u003cKeyCode\u003e\u003e) {\n    if keys.just_pressed(KeyCode::S) {\n        commands.save::\u003cMySnap\u003e();\n    }\n}\n```\n\nThis will generate an event with the snapshot in it.  You can do whatever you\nwant with it. Save it in a resource, to disk, or add it to a stack if you are\nimplementing undo.\n\n```rust\nfn store_snapshot(\n    mut save_events: EventReader\u003cSaveEvent\u003cMySnap\u003e\u003e,\n    mut save_slot: ResMut\u003cSaveSlot\u003e,\n) {\n    for save_event in save_events.iter() {\n        save_slot.0 = save_event.snapshot.clone();\n    }\n}\n```\n\nWhen you want to load the snapshot, it's as simple as invoking the `.load()`\ncommand with the snapshot:\n\n```rust\nfn load_key(\n    mut commands: Commands,\n    mut save_slot: ResMut\u003cSaveSlot\u003e,\n    keys: Res\u003cInput\u003cKeyCode\u003e\u003e,\n)\n    if keys.just_pressed(KeyCode::L) {\n        commands.load::\u003cMySnap\u003e(save_slot.0.clone())\n    }\n}\n```\n\nSee the [`basic.rs`](./examples/basic.rs) for a complete example very similar to\nthe above.\n\n## Supported bevy versions\n\n|bevy|bevy_pkv|\n|---|---|\n|0.7|0.2,main|\n|0.6|0.1|\n\n## Thanks!\n\nThe core part of this crate is based on code from\n[`bevy_ggrs`](https://github.com/gschup/bevy_ggrs).\n\n## License\n\nAll code in this repository dual-licensed under either:\n\n- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)\n- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohanhelsing%2Fbevy_snap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohanhelsing%2Fbevy_snap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohanhelsing%2Fbevy_snap/lists"}