Bevy, a new Rust game engine and ECS, has a feature where it "scopes" its systems based on the type of the arguments. From its docs:
The parameters we pass in to a "system function" define what entities the system runs on. In this case, greet_people will run on all entities with the Person and Name component.
It looks like this:
struct Person;
struct Name(String);
fn greet_people(person: &Person, name: &Name) {
println!("hello {}", name.0);
}
How is Bevy able to make this happen? I thought I read somewhere that Rust didn't support reflection in this way.
Bevy defines a set of traits (IntoQuerySystem
and ) that are implemented by functions that match those signatures. Those traits are then exported by the Bevy prelude. One of the limitations of this is that you can only convert functions up to a certain number of arguments into systems, and the arguments must be in a particular order ([command?], [resources...], [queries/components...]).IntoForEachSystem
Edit: For-each systems were deprecated in Bevy 0.4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With