Crates.io | commands_send_event |
lib.rs | commands_send_event |
version | 0.6.0 |
source | src |
created_at | 2022-03-07 09:17:35.473244 |
updated_at | 2022-11-16 08:16:16.117407 |
description | Bevy generic event dispatcher extension trait |
homepage | |
repository | https://github.com/ickshonpe/commands_send_event |
max_upload_size | |
id | 544913 |
size | 58,729 |
An extension trait for Commands that allows you to send events from a system without having to retrieve a typed EventWriter SystemParam.
Add to your project with the command
cargo add commands_send_event
or add directly add the dependency to your Cargo.toml
[dependencies.commands_send_event]
version = "0.6"
then the send_event
method is available on Commands:
use commands_send_event::CommandsSendEvent;
#[derive(Component)]
struct MyEventA(String);
#[derive(Component)]
struct MyEventB(i32);
fn sender(
mut commands: Commands
) {
commands.send_event(MyEventA("Hello, World"));
commands.send_event(MyEventB(42));
}
The /examples
folder has two examples you can run with:
cargo run --example basic_usage
cargo run --example schedule
AnyEventWriter is a facade over Commands that implements SystemParam.
This crate is a bit redundant now since Bevy 0.8 as sending events using World
is very easy. With commands.add
you can queue a closure to dispatch an event like so:
commands.add(|world: &mut World|
world.send_event(MyEvent)
);