3 unstable releases
0.2.0 | Sep 12, 2023 |
---|---|
0.1.1 | Jun 22, 2023 |
0.1.0 | Jun 22, 2023 |
#2322 in Game dev
28KB
bevy_oneshot
Naive implementation of one-shot systems for Bevy
Why?
The library is made mainly for the convenience of working with the GUI. Remember that feeling when you created a system that creates GUI with a couple of input parameters? Nothing foretold trouble, but then the first button appears in the interface, the processing of which adds a few arguments to the system. The second button needed a resource, the third needed a query. After the fourth button you get a clippy::too_many_arguments warn... Pretty frustrating, huh?
With bevy_oneshot
you can put all the arguments a particular button needs into a separate system, or even not write a system at all, by making a lambda, which greatly reduces the amount of unnecessary stuff in the system scope.
I really hope one-shot systems will be introduced in Bevy soon and this crate will become irrelevant.
Installation
cargo add bevy_oneshot
or add this to your Cargo.toml
[dependencies]
bevy_oheshot = "0.2"
Usage
use bevy::prelude::*;
use bevy_oneshot::CommandRunOnce;
fn some_system(mut commands: Commands) {
// run once without arguments
commands.run_once(|_query: Query<&Window>| {
// your code here
});
// run once with input arguments
commands.run_once_with(
|input: In<u32>| {
println!("{}", input.0);
},
42,
);
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(some_system)
.run();
}
Compatibility
Bevy Version | Plugin Version |
---|---|
0.10 |
0.1.0-0.1.1 |
0.11 |
0.2.0 |
Contributing
PRs are very welcome.
Dependencies
~21–30MB
~477K SLoC