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
Data field should be optional #2
Comments
You mean as in setting the data type to |
Yes! As I prepared the example for issue #3 I thought it might have been nicer to not write |
Fixed by #5. Spawning functions are now just regular old Bevy systems with the user data being passed as an New minimal example: use bevy::prelude::*;
use spew::prelude::*;
#[derive(Debug, Eq, PartialEq)]
enum Object {
Cube,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(SpewPlugin::<Object>::default())
.add_spawner((Object::Cube, spawn_cube))
.add_system(spawn_something.on_startup())
.run();
}
fn spawn_something(mut spawn_events: EventWriter<SpawnEvent<Object>>) {
spawn_events.send(SpawnEvent::new(Object::Cube));
}
fn spawn_cube(mut commands: Commands) {
info!("Spawning cube");
commands.spawn(Name::new("Cube"));
} New example with user data: use bevy::prelude::*;
use spew::prelude::*;
#[derive(Debug, Eq, PartialEq)]
enum Object {
Cube,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(SpewPlugin::<Object, Transform>::default())
.add_spawners(((Object::Cube, spawn_cube_with_transform),))
.add_system(spawn_something_with_transform.on_startup())
.run();
}
fn spawn_something_with_transform(mut spawn_events: EventWriter<SpawnEvent<Object, Transform>>) {
spawn_events.send(SpawnEvent::with_data(
Object::Cube,
Transform::from_xyz(1.0, 2.0, 3.0),
));
}
fn spawn_cube_with_transform(In(transform): In<Transform>, mut commands: Commands) {
info!("Spawning cube at {}", transform.translation);
commands.spawn((Name::new("Cube"), transform));
} |
This is only my opinion so feel free to just close this issue :)
The problem
There are quite a lot of objects that don't need any input to be initialized because they are always initialized in the same way,
or only depend on a resource which would have to be fetched by the world in the spawn function anyway (I guess?).
I think a more idiomatic way would be to model it similar to how
Query
in bevy are modeled with the default value()
if not given otherwise (for the filtering)The text was updated successfully, but these errors were encountered: