Struct bevy_ecs::system::Commands[][src]

pub struct Commands<'a> { /* fields omitted */ }

A list of commands that will be run to modify a World

Implementations

impl<'a> Commands<'a>[src]

pub fn new(queue: &'a mut CommandQueue, world: &'a World) -> Self[src]

pub fn spawn(&mut self) -> EntityCommands<'a, '_>[src]

Creates a new empty entity and returns an EntityCommands builder for it.

Example

use bevy_ecs::prelude::*;

fn example_system(mut commands: Commands) {
    // Create a new empty entity and retrieve its id.
    let empty_entity = commands.spawn().id();

    // Create another empty entity, then add some component to it
    commands.spawn()
        // adds a new component bundle to the entity
        .insert_bundle((1usize, 2u32))
        // adds a single component to the entity
        .insert("hello world");
}

pub fn spawn_bundle<'b, T: Bundle>(
    &'b mut self,
    bundle: T
) -> EntityCommands<'a, 'b>
[src]

Creates a new entity with the components contained in bundle.

This returns an EntityCommands builder, which enables inserting more components and bundles using a “builder pattern”.

Note that bundle is a Bundle, which is a collection of components. Bundle is automatically implemented for tuples of components. You can also create your own bundle types by deriving Bundle.

Example

use bevy_ecs::prelude::*;

struct Component1;
struct Component2;

#[derive(Bundle)]
struct ExampleBundle {
    a: Component1,
    b: Component2,
}

fn example_system(mut commands: Commands) {
    // Create a new entity with a component bundle.
    commands.spawn_bundle(ExampleBundle {
        a: Component1,
        b: Component2,
    });

    commands
        // Create a new entity with two components using a "tuple bundle".
        .spawn_bundle((Component1, Component2))
        // spawn_bundle returns a builder, so you can insert more bundles like this:
        .insert_bundle((1usize, 2u32))
        // or insert single components like this:
        .insert("hello world");
}

pub fn entity(&mut self, entity: Entity) -> EntityCommands<'a, '_>[src]

Returns an EntityCommands builder for the requested entity.

Example

use bevy_ecs::prelude::*;

fn example_system(mut commands: Commands) {
    // Create a new, empty entity
    let entity = commands.spawn().id();

    commands.entity(entity)
        // adds a new component bundle to the entity
        .insert_bundle((1usize, 2u32))
        // adds a single component to the entity
        .insert("hello world");
}

pub fn spawn_batch<I>(&mut self, bundles_iter: I) where
    I: IntoIterator + Send + Sync + 'static,
    I::Item: Bundle
[src]

Equivalent to iterating bundles_iter and calling Self::spawn on each bundle, but slightly more performant.

pub fn insert_resource<T: Component>(&mut self, resource: T)[src]

pub fn remove_resource<T: Component>(&mut self)[src]

pub fn add<C: Command>(&mut self, command: C)[src]

Adds a command directly to the command list. Prefer this to [Self::add_command_boxed] if the type of command is statically known.

Trait Implementations

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Commands<'a>

impl<'a> Send for Commands<'a>

impl<'a> Sync for Commands<'a>

impl<'a> Unpin for Commands<'a>

impl<'a> !UnwindSafe for Commands<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Component for T where
    T: 'static + Send + Sync
[src]

impl<T> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Any + Send + Sync
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,