Expand description
§Bevy_trait
Macros for creating Traits in Bevy.
§System
Turn a trait fn into a Bevy system
ⓘ
trait Interactive {
#[system]
fn update(damage: f32);
}
/*
// Desugars to
trait Interactive {
fn update(damage: f32) -> impl System;
}
*/
#[derive(Component)]
struct Health(f32);
#[derive(Component, Copy, Clone)]
struct Cactus;
impl Interactive for Cactus {
#[system(damage: f32)]
fn update(
cacti: Query<&GlobalTransform, With<Cactus>>,
creatures: Query<(&GlobalTransform, &mut Health), Without<Cactus>>,
) {
// This is a normal Bevy system and accepts SystemParams as such.
for cactus_gtf in &cacti {
info!("Damage {:?}", damage); // You can also use params passed into the System builder.
// ...
}
}
}
fn run() {
let system = Cactus::update(42); // This is a System ...
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Update, system) // ... that you can add to an App
.run();
}§Compatibility
Since bevy_trait does not rely on bevy directly, it is typically compatible across many different versions.
| Bevy Version | Crate Version |
|---|---|
0.15 | 0.3 |
0.10, 0.11, 0.12, 0.13, 0.14 | 0.1, 0.2 |
§License
bevy_trait is dual-licensed under MIT and Apache-2.0.
Attribute Macros§
- boxed_
readonly_ system - Attribute to use a Trait fn like it’s a boxed
ReadOnlySystem. - boxed_
readonly_ system_ with_ input - Attribute to use a Trait fn like it’s a boxed
ReadOnlySystem, withSystemInput. - boxed_
system - Attribute to use a Trait fn like it’s a boxed
System. - boxed_
system_ with_ input - Attribute to use a Trait fn like it’s a boxed
System, withSystemInput. - readonly_
system - Attribute to use a Trait fn like it’s a
ReadOnlySystem. - readonly_
system_ with_ input - Attribute to use a Trait fn like it’s a
ReadOnlySystem, withSystemInput. - system
- Attribute to use a Trait fn like it’s a
System. - system_
with_ input - Attribute to use a Trait fn like it’s a
System, withSystemInput.