Crates.io | bevy_gltf_save_load |
lib.rs | bevy_gltf_save_load |
version | 0.5.0 |
source | src |
created_at | 2024-01-10 13:21:05.497898 |
updated_at | 2024-07-18 23:22:37.236922 |
description | Save & load your bevy games |
homepage | https://github.com/kaosat-dev/Blender_bevy_components_workflow |
repository | https://github.com/kaosat-dev/Blender_bevy_components_workflow |
max_upload_size | |
id | 1095231 |
size | 46,122 |
bevy_gltf_save_load has been deprecated in favor of its successor Blenvy, part of the Blenvy project. No further development or maintenance will be done for Bevy bevy_gltf_save_load. See #194 for background.
Built upon bevy_gltf_blueprints this crate adds the ability to easilly save and load your game worlds for Bevy .
Particularly useful when using Blender as an editor for the Bevy game engine, combined with the Blender plugin that does a lot of the work for you (including spliting generating seperate gltf files for your static vs dynamic assets)
A bit of heads up:
very opinionated !
still in the early stages & not 100% feature complete
fun fact: as the static level structure is stored seperatly, you can change your level layout & still reload an existing save file
Here's a minimal usage example:
# Cargo.toml
[dependencies]
bevy="0.14"
bevy_gltf_save_load = "0.5"
bevy_gltf_blueprints = "0.11" // also needed
use bevy::prelude::*;
use bevy_gltf_save_load::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
SaveLoadPlugin::default()
))
.run();
}
// add a system to trigger saving
pub fn request_save(
mut save_requests: EventWriter<SaveRequest>,
keycode: Res<Input<KeyCode>>,
)
{
if keycode.just_pressed(KeyCode::S) {
save_requests.send(SaveRequest {
path: "save.scn.ron".into(),
})
}
}
// add a system to trigger loading
pub fn request_load(
mut load_requests: EventWriter<LoadRequest>,
keycode: Res<Input<KeyCode>>,
)
{
if keycode.just_pressed(KeyCode::L) {
save_requests.send(LoadRequest {
path: "save.scn.ron".into(),
})
}
}
// setting up your world
// on initial setup, the static entities & the dynamic entities are kept seperate for clarity & loaded as blueprints from 2 seperate files
pub fn setup_game(
mut commands: Commands,
mut next_game_state: ResMut<NextState<GameState>>,
) {
info!("setting up game world");
// here we actually spawn our game world/level
let world_root = commands
.spawn((
Name::from("world"),
GameWorldTag,
InAppRunning,
TransformBundle::default(),
InheritedVisibility::default(),
))
.id();
// and we fill it with static entities
let static_data = commands
.spawn((
Name::from("static"),
BluePrintBundle {
blueprint: BlueprintName("World".to_string()),
..Default::default()
},
StaticEntitiesRoot,
Library("models".into())
))
.id();
// and we fill it with dynamic entities
let dynamic_data = commands
.spawn((
Name::from("dynamic"),
BluePrintBundle {
blueprint: BlueprintName("World_dynamic".to_string()),
..Default::default()
},
DynamicEntitiesRoot,
NoInBlueprint,
Library("models".into())
))
.id();
commands.entity(world_root).add_child(static_data);
commands.entity(world_root).add_child(dynamic_data);
next_game_state.set(GameState::InGame)
}
take a look at the example for more clarity
Add the following to your [dependencies]
section in Cargo.toml
:
bevy_gltf_save_load = "0.3"
bevy_gltf_blueprints = "0.10" // also needed, as bevy_gltf_save_load does not re-export it at this time
Or use cargo add
:
cargo add bevy_gltf_save_load
use bevy::prelude::*;
use bevy_gltf_save_load::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins
SaveLoadPlugin::default()
))
.run();
}
you likely need to configure your settings (otherwise, not much will be saved)
use bevy::prelude::*;
use bevy_gltf_save_load::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
SaveLoadPlugin {
save_path: "scenes".into(), // where do we save files to (under assets for now) defaults to "scenes"
component_filter: SceneFilter::Allowlist(HashSet::from([ // this is using Bevy's build in SceneFilter, you can compose what components you want to allow/deny
TypeId::of::<Name>(),
TypeId::of::<Transform>(),
TypeId::of::<Velocity>(),
// and any other commponent you want to include/exclude
])),
resource_filter: SceneFilter::deny_all(), // same logic as above, but for resources : also be careful & remember to register your resources !
..Default::default()
},
// you need to configure the blueprints plugin as well (might be pre_configured in the future, but for now you need to do it manually)
BlueprintsPlugin {
library_folder: "models/library".into(),
format: GltfFormat::GLB,
aabbs: true,
..Default::default()
},
))
.run();
}
by default only the following components are going to be saved
you CANNOT remove these as they are part of the boilerplate
you CAN add however many other components you want, allow them all etc as you see fit
you can find more information about the SceneFilter object here and here
SaveRequest
event// add a system to trigger saving
pub fn request_save(
mut save_requests: EventWriter<SaveRequest>,
keycode: Res<Input<KeyCode>>,
)
{
if keycode.just_pressed(KeyCode::S) {
save_requests.send(SaveRequest {
path: "save.scn.ron".into(),
})
}
}
LoadRequest
event// add a system to trigger saving
pub fn request_load(
mut load_requests: EventWriter<LoadRequest>,
keycode: Res<Input<KeyCode>>,
)
{
if keycode.just_pressed(KeyCode::L) {
save_requests.send(LoadRequest {
path: "save.scn.ron".into(),
})
}
}
SavingFinished
for savingLoadingFinished
for loadingNote: I highly recomend you change states when you start/finish saving & loading, otherwise things will get unpredictable Please see the example for this.
For convenience bevy_gltf_save_load
provides two SystemSets
Highly advised to get a better understanding of how things work ! To get started I recomend looking at
All examples are here:
The main branch is compatible with the latest Bevy release, while the branch bevy_main
tries to track the main
branch of Bevy (PRs updating the tracked commit are welcome).
Compatibility of bevy_gltf_save_load
versions:
bevy_gltf_save_load |
bevy |
---|---|
0.5 |
0.14 |
0.4 |
0.13 |
0.1 -0.3 |
0.12 |
branch main |
0.12 |
branch bevy_main |
main |
This crate, all its code, contents & assets is Dual-licensed under either of