-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems loading scene #166
Comments
Sorry for the late reply! Would you mind telling me if you are still experiencing this issue with latest Bevy? |
Regarding the saving part, this is related to #1442 , just posting it here as reference. See also https://discord.com/channels/691052431525675048/692648082499829760/838080584190132274 about a discussion on direct world access vs the solution proposed in 1442. |
Updating this to Bevy 0.5 everything works as expected: use std::{fs::File, io::Write};
use bevy::prelude::*;
use bevy::reflect::*;
#[derive(Default, Reflect)]
#[reflect(Component)]
struct Player;
#[derive(Default, Reflect)]
#[reflect(Component)]
struct Enemy;
#[derive(Default, Reflect)]
#[reflect(Component)]
struct Health(u8);
fn test_world(mut commands: Commands) {
commands.spawn_bundle(OrthographicCameraBundle::new_2d());
commands.spawn_bundle((Player, Health(100)));
commands.spawn_bundle((Enemy, Health(100)));
}
fn load_world(asset_server: Res<AssetServer>, mut scene_spawner: ResMut<SceneSpawner>) {
let scene_handle: Handle<DynamicScene> = asset_server.load("scenes/start_scene.scn.ron");
scene_spawner.spawn_dynamic(scene_handle);
println!("loaded");
asset_server.watch_for_changes().unwrap();
}
fn print_system(query: Query<Entity>) {
for entity in &mut query.iter() {
println!(" Entity({})", entity.id());
}
}
fn save_scene(world: &mut World) {
let type_registry = world.get_resource::<TypeRegistryArc>().unwrap();
let scene = DynamicScene::from_world(&world, &type_registry);
let mut file = File::create("assets/scenes/start_scene.scn.ron").unwrap();
file.write_all(
scene
.serialize_ron(&type_registry)
.unwrap()
.as_bytes(),
)
.unwrap();
}
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.register_type::<Health>()
.register_type::<Player>()
.register_type::<Enemy>()
// This startup system is replaced with test_world the first time so the file can be saved
.add_startup_system(load_world.system())
// Uncomment to create save file.
//.add_startup_system(test_world.system())
//.add_system(save_scene.exclusive_system().at_end())
.add_system(print_system.system())
.run();
} |
Closing as resolved <3 |
Resolve merge conflicts in `lienar-rgba-everywhere`
Hello!
I have been trying out the scene loader and ran into some issues where no entities would be loaded at all. Here is a minimal example:
If I omit spawning the
Camera2dComponents
everything works as expected and the entities are spawned but if I leave it in I get no errors but no entities are actually loaded to the world. I was under the impression that I shouldn't have to register components that are "built in" to the engine. Is there something else I am missing? Here is the code I use to save the world (I use keyboard input to initiate the save logic but details are omitted):The text was updated successfully, but these errors were encountered: