[][src]Struct bevy_ecs::Commands

pub struct Commands { /* fields omitted */ }

A list of commands that will be run to populate a World and Resources.

Implementations

impl Commands[src]

pub fn spawn(
    &mut self,
    bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Self
[src]

Creates a new entity with the components contained in bundle.

Note that bundle is a DynamicBundle, which is a collection of components. DynamicBundle is automatically implemented for tuples of components. You can also create your own bundle types by deriving Bundle. If you would like to spawn an entity with a single component, consider wrapping the component in a tuple (which DynamicBundle is implemented for).

See Self::set_current_entity, Self::insert.

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(ExampleBundle {
        a: Component1,
        b: Component2,
    });

    // Create a new entity with a single component.
    commands.spawn((Component1,));
    // Create a new entity with two components.
    commands.spawn((Component1, Component2));
}

pub fn spawn_batch<I>(&mut self, bundles_iter: I) -> &mut Self 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 despawn(&mut self, entity: Entity) -> &mut Self[src]

Despawns only the specified entity, not including its children.

pub fn insert(
    &mut self,
    entity: Entity,
    bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Self
[src]

Inserts a bundle of components into entity.

See World::insert.

pub fn insert_one(
    &mut self,
    entity: Entity,
    component: impl Component
) -> &mut Self
[src]

Inserts a single component into entity.

See World::insert_one.

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

pub fn insert_local_resource<T: Resource>(
    &mut self,
    system_id: SystemId,
    resource: T
) -> &mut Self
[src]

Insert a resource that is local to a specific system.

See crate::System::id.

pub fn remove_one<T>(&mut self, entity: Entity) -> &mut Self where
    T: Component
[src]

pub fn remove<T>(&mut self, entity: Entity) -> &mut Self where
    T: Bundle + Send + Sync + 'static, 
[src]

pub fn with_bundle(
    &mut self,
    bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Self
[src]

Adds a bundle of components to the current entity.

See Self::with, Self::current_entity.

pub fn with(&mut self, component: impl Component) -> &mut Self[src]

Adds a single component to the current entity.

See Self::with_bundle, Self::current_entity.

Warning

It's possible to call this with a bundle, but this is likely not intended and Self::with_bundle should be used instead. If with is called with a bundle, the bundle itself will be added as a component instead of the bundles' inner components each being added.

Example

with can be chained with Self::spawn.

use bevy_ecs::prelude::*;

struct Component1;
struct Component2;

fn example_system(mut commands: Commands) {
    // Create a new entity with a `Component1` and `Component2`.
    commands.spawn((Component1,)).with(Component2);

    // Psst! These are also equivalent to the line above!
    commands.spawn((Component1, Component2));
    commands.spawn(()).with(Component1).with(Component2);
    #[derive(Bundle)]
    struct ExampleBundle {
        a: Component1,
        b: Component2,
    }
    commands.spawn(()).with_bundle(ExampleBundle {
        a: Component1,
        b: Component2,
    });
}

pub fn add_command<C: Command + 'static>(&mut self, command: C) -> &mut Self[src]

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

pub fn add_command_boxed(&mut self, command: Box<dyn Command>) -> &mut Self[src]

pub fn apply(&mut self, world: &mut World, resources: &mut Resources)[src]

Runs all the stored commands on world and resources. The command buffer is emptied as a part of this call.

pub fn current_entity(&self) -> Option<Entity>[src]

Returns the current entity, set by Self::spawn or with Self::set_current_entity.

pub fn set_current_entity(&mut self, entity: Entity)[src]

pub fn clear_current_entity(&mut self)[src]

pub fn for_current_entity(&mut self, f: impl FnOnce(Entity)) -> &mut Self[src]

pub fn set_entity_reserver(&mut self, entity_reserver: EntityReserver)[src]

Trait Implementations

impl Default for Commands[src]

impl<'a> SystemParam for &'a mut Commands[src]

Auto Trait Implementations

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> Downcast for T where
    T: Any
[src]

impl<T> DowncastSync for T where
    T: Send + Sync + Any
[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>,