[−][src]Struct bevy_ecs::Commands
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]
&mut self,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Self
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]
I: IntoIterator + Send + Sync + 'static,
I::Item: Bundle,
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]
&mut self,
entity: Entity,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Self
Inserts a bundle of components into entity.
See World::insert.
pub fn insert_one(
&mut self,
entity: Entity,
component: impl Component
) -> &mut Self[src]
&mut self,
entity: Entity,
component: impl Component
) -> &mut Self
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]
&mut self,
system_id: SystemId,
resource: T
) -> &mut Self
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]
T: Component,
See World::remove_one.
pub fn remove<T>(&mut self, entity: Entity) -> &mut Self where
T: Bundle + Send + Sync + 'static, [src]
T: Bundle + Send + Sync + 'static,
See World::remove.
pub fn with_bundle(
&mut self,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Self[src]
&mut self,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Self
Adds a bundle of components to the 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]
See Self::add_command.
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]
type Fetch = FetchCommands
Auto Trait Implementations
impl !RefUnwindSafe for Commands[src]
impl Send for Commands[src]
impl Sync for Commands[src]
impl Unpin for Commands[src]
impl !UnwindSafe for Commands[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Downcast for T where
T: Any, [src]
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>[src]
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>[src]
pub fn as_any(&self) -> &(dyn Any + 'static)[src]
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)[src]
impl<T> DowncastSync for T where
T: Send + Sync + Any, [src]
T: Send + Sync + Any,
impl<T> From<T> for T[src]
impl<T> Instrument for T[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>[src]
pub fn in_current_span(self) -> Instrumented<Self>[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,