Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ickshonpe/commands_send_event
Send Bevy Events generically through Commands
https://github.com/ickshonpe/commands_send_event
bevy
Last synced: 1 day ago
JSON representation
Send Bevy Events generically through Commands
- Host: GitHub
- URL: https://github.com/ickshonpe/commands_send_event
- Owner: ickshonpe
- License: mit
- Created: 2022-03-07T08:57:04.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-16T08:15:44.000Z (about 2 years ago)
- Last Synced: 2024-11-11T23:10:04.217Z (about 1 month ago)
- Topics: bevy
- Language: Rust
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Commands Send Event
An extension trait for Commands that allows you to send events from a system without having to retrieve a typed EventWriter SystemParam.
* version 0.9 supports Bevy 0.9
* version 0.5 supports Bevy 0.8
* version 0.3 & 0.4 support Bevy 0.7
* versions <0.3 support Bevy 0.6## Limitations
* Events won't be dispatched immediately, but at the next Stage boundary when the queued commands are applied to the World.
#
## Usage
Add to your project with the command
```
cargo add commands_send_event
```or add directly add the dependency to your Cargo.toml
```toml
[dependencies.commands_send_event]
version = "0.6"
```then the ```send_event``` method is available on Commands:
```rust
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.
#
## NoteThis 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:
```rust
commands.add(|world: &mut World|
world.send_event(MyEvent)
);
```