
Bevy Events Messaging
Bevy ECS skill for messages and observers.
Install
npx skills add thedivergentai/Game-Dev-Agentic-Skills --skill bevy-events-messaging -g -a claude-code -y- Repository
- thedivergentai/Game-Dev-Agentic-Skills917
- Category
- Engineering
- Updated
- 19d ago
- License
- LGPL-3.0
- Context cost
- Mediumabout 1,710 tokens
- Runs scripts
- No, instructions only
What it does
Bevy ECS skill for messages and observers. Keywords: Bevy, Message, Event, Observer.
Bevy events and messaging
When to use
Load this when one system should notice that something happened without storing that fact on every entity. Pick the mechanism from the pages below. Do not invent a third channel.
ECS shape
- Messages (pull).
Messageis a buffered message for pull-based handling.MessageWriterwrites.MessageReaderreads and tracks what it already saw.Messagesholds what occurred within the last two updates. Register the type withApp::add_message. The engine updates the buffer; gameplay systems only write and read. - Events (push). Derive
Event, add an observer, trigger.Commands::triggerandWorld::triggerrun observers immediately inside the call.On<E>is the system parameter.Event::Triggerdefaults toGlobalTriggerfor derived events. - Observers. An
Observeris a component that holds a system.EntityEventtargets one entity: the event carries theentityfield, andOn::event_targetreturns it. - State transitions.
StateTransitionEvent<S>fires when stateSchanges. That type lives with states. See bevy-state-machines.
Examples
[dependencies]
bevy = "0.20"
A hit is a fact other systems poll. Register the message, write it from the strike system, and read it later in the same schedule. add_message keeps the double-buffered queue.
#[derive(Message)]
struct Hit {
amount: i32,
}
fn install(app: &mut App) {
app.add_message::<Hit>()
.add_systems(Update, (deal, apply).chain());
}
fn deal(mut hits: MessageWriter<Hit>) {
hits.write(Hit { amount: 12 });
}
fn apply(mut hits: MessageReader<Hit>) {
for hit in hits.read() {
info!("hit {}", hit.amount);
}
}
A shout should run listeners now. Derive Event, observe with On<Shout>, and trigger. The observer runs inside trigger before the system returns.
#[derive(Event)]
struct Shout {
text: String,
}
