[−]Struct bevy::prelude::Commands
A list of commands that will be run to populate a World
and Resources
.
Implementations
impl Commands
pub fn spawn(
&mut self,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Commands
&mut self,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Commands
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 Commands where
I: IntoIterator + Send + Sync + 'static,
<I as IntoIterator>::Item: Bundle,
I: IntoIterator + Send + Sync + 'static,
<I as IntoIterator>::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 Commands
Despawns only the specified entity, not including its children.
pub fn insert(
&mut self,
entity: Entity,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Commands
&mut self,
entity: Entity,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Commands
Inserts a bundle of components into entity
.
See World::insert
.
pub fn insert_one(
&mut self,
entity: Entity,
component: impl Component
) -> &mut Commands
&mut self,
entity: Entity,
component: impl Component
) -> &mut Commands
Inserts a single component into entity
.
See World::insert_one
.
pub fn insert_resource<T>(&mut self, resource: T) -> &mut Commands where
T: Resource,
T: Resource,
pub fn insert_local_resource<T>(
&mut self,
system_id: SystemId,
resource: T
) -> &mut Commands where
T: Resource,
&mut self,
system_id: SystemId,
resource: T
) -> &mut Commands where
T: Resource,
Insert a resource that is local to a specific system.
See crate::System::id
.
pub fn remove_one<T>(&mut self, entity: Entity) -> &mut Commands where
T: Component,
T: Component,
See World::remove_one
.
pub fn remove<T>(&mut self, entity: Entity) -> &mut Commands where
T: Bundle + Send + Sync + 'static,
T: Bundle + Send + Sync + 'static,
See World::remove
.
pub fn with_bundle(
&mut self,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Commands
&mut self,
bundle: impl DynamicBundle + Send + Sync + 'static
) -> &mut Commands
Adds a bundle of components to the current entity.
pub fn with(&mut self, component: impl Component) -> &mut Commands
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>(&mut self, command: C) -> &mut Commands where
C: 'static + Command,
C: 'static + Command,
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 + 'static, Global>
) -> &mut Commands
&mut self,
command: Box<dyn Command + 'static, Global>
) -> &mut Commands
See Self::add_command
.
pub fn apply(&mut self, world: &mut World, resources: &mut Resources)
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>
Returns the current entity, set by Self::spawn
or with Self::set_current_entity
.
pub fn set_current_entity(&mut self, entity: Entity)
pub fn clear_current_entity(&mut self)
pub fn for_current_entity(&mut self, f: impl FnOnce(Entity)) -> &mut Commands
pub fn set_entity_reserver(&mut self, entity_reserver: EntityReserver)
Trait Implementations
impl BuildChildren for Commands
pub fn with_children(
&mut self,
parent: impl FnOnce(&mut ChildBuilder<'_>)
) -> &mut Commands
&mut self,
parent: impl FnOnce(&mut ChildBuilder<'_>)
) -> &mut Commands
pub fn push_children(
&mut self,
parent: Entity,
children: &[Entity]
) -> &mut Commands
&mut self,
parent: Entity,
children: &[Entity]
) -> &mut Commands
pub fn insert_children(
&mut self,
parent: Entity,
index: usize,
children: &[Entity]
) -> &mut Commands
&mut self,
parent: Entity,
index: usize,
children: &[Entity]
) -> &mut Commands
impl Default for Commands
impl DespawnRecursiveExt for Commands
pub fn despawn_recursive(&mut self, entity: Entity) -> &mut Commands
Despawns the provided entity and its children.
impl SpawnSceneCommands for Commands
pub fn spawn_scene(&mut self, scene_handle: Handle<Scene>) -> &mut Commands
impl<'a> SystemParam for &'a mut Commands
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> Any for T where
T: Any,
T: Any,
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> Component for T where
T: 'static + Send + Sync,
T: 'static + Send + Sync,
impl<T> Downcast for T where
T: Any,
T: Any,
pub fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn as_any(&self) -> &(dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
impl<T> DowncastSync for T where
T: Send + Sync + Any,
T: Send + Sync + Any,
impl<T> From<T> for T
[src]
impl<T> FromResources for T where
T: Default,
T: Default,
pub fn from_resources(_resources: &Resources) -> T
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
pub fn in_current_span(self) -> Instrumented<Self>ⓘNotable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
[src]
Notable traits for Instrumented<T>
impl<T> Future for Instrumented<T> where
T: Future, type Output = <T as Future>::Output;
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Resource for T where
T: 'static + Send + Sync,
T: 'static + Send + Sync,
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>,