Struct bevy::ecs::system::Commands [−]
A list of commands that will be run to modify a World
Implementations
impl<'a> Commands<'a>
pub fn new(queue: &'a mut CommandQueue, world: &'a World) -> Commands<'a>
pub fn spawn(&mut self) -> EntityCommands<'a, '_>
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<T>(&'b mut self, bundle: T) -> EntityCommands<'a, 'b> where
T: Bundle,
T: Bundle,
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, '_>
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 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 insert_resource<T>(&mut self, resource: T) where
T: Component,
T: Component,
pub fn remove_resource<T>(&mut self) where
T: Component,
T: Component,
pub fn add<C>(&mut self, command: C) where
C: Command,
C: Command,
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
impl<'a> SpawnSceneCommands for Commands<'a>
pub fn spawn_scene(&mut self, scene_handle: Handle<Scene>)
impl<'a> SystemParam for Commands<'a>
type Fetch = CommandQueue
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]
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> Downcast<T> for T
impl<T> DowncastSync for T where
T: Any + Send + Sync,
T: Any + Send + Sync,
impl<T> From<T> for T
[src]
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, 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<T> Upcast<T> for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,