#command #bevy #macro #bundle #methods #world #derive

macro bevy_derive_commands

A macro for creating bevy Commands methods

3 releases

0.1.2 Dec 10, 2023
0.1.1 Dec 10, 2023
0.1.0 Dec 10, 2023

#550 in Procedural macros

42 downloads per month

MIT/Apache

7KB
109 lines

crates.io

Derive macro for creating bevy Commands methods.

Example

use bevy_derive_commands::*;

/// A command that spawns a bundle `n` times
#[command]
fn create_stuff<B: Bundle + Clone>(world: &mut World, bundle: B, n: usize) {
    for _ in 0..times {
        world.spawn(bundle.clone());
    }
}

fn setup(mut commands: Commands) {
    // Use the generated method
    commands.create_stuff(TransformBundle::default(), 3);
    // Or add the generated command type directly
    commands.add(CreateStuffCommand { bundle: TransformBundle::default(), n: 3 });
}

Compatibility

Bevy Crate
0.12 0.1

Dependencies

~0.5–1MB
~21K SLoC