pub struct EntityEntryCommands<'a, T> { /* private fields */ }Expand description
A wrapper around EntityCommands with convenience methods for working with a specified component type.
Implementations§
Source§impl<'a, T: Component<Mutability = Mutable>> EntityEntryCommands<'a, T>
impl<'a, T: Component<Mutability = Mutable>> EntityEntryCommands<'a, T>
Source§impl<'a, T: Component> EntityEntryCommands<'a, T>
impl<'a, T: Component> EntityEntryCommands<'a, T>
Sourcepub fn or_insert(&mut self, default: T) -> &mut Self
pub fn or_insert(&mut self, default: T) -> &mut Self
Insert default into this entity,
if T is not already present.
Sourcepub fn or_try_insert(&mut self, default: T) -> &mut Self
pub fn or_try_insert(&mut self, default: T) -> &mut Self
Sourcepub fn or_insert_with<F>(&mut self, default: F) -> &mut Self
pub fn or_insert_with<F>(&mut self, default: F) -> &mut Self
Insert the value returned from default into this entity,
if T is not already present.
default will only be invoked if the component will actually be inserted.
Sourcepub fn or_try_insert_with<F>(&mut self, default: F) -> &mut Self
pub fn or_try_insert_with<F>(&mut self, default: F) -> &mut Self
Sourcepub fn or_default(&mut self) -> &mut Selfwhere
T: Default,
pub fn or_default(&mut self) -> &mut Selfwhere
T: Default,
Insert T::default into this entity,
if T is not already present.
T::default will only be invoked if the component will actually be inserted.
Sourcepub fn or_from_world(&mut self) -> &mut Selfwhere
T: FromWorld,
pub fn or_from_world(&mut self) -> &mut Selfwhere
T: FromWorld,
Insert T::from_world into this entity,
if T is not already present.
T::from_world will only be invoked if the component will actually be inserted.
Sourcepub fn entity(&mut self) -> EntityCommands<'_>
pub fn entity(&mut self) -> EntityCommands<'_>
Get the EntityCommands from which the EntityEntryCommands was initiated.
This allows you to continue chaining method calls after calling EntityCommands::entry.
§Example
#[derive(Component)]
struct Level(u32);
fn level_up_system(mut commands: Commands, player: Res<PlayerEntity>) {
commands
.entity(player.entity)
.entry::<Level>()
// Modify the component if it exists.
.and_modify(|mut lvl| lvl.0 += 1)
// Otherwise, insert a default value.
.or_insert(Level(0))
// Return the EntityCommands for the entity.
.entity()
// Continue chaining method calls.
.insert(Name::new("Player"));
}