Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1231,15 +1231,32 @@ impl<'a> EntityCommands<'a> {
/// #[derive(Component)]
/// struct Level(u32);
///
///
/// #[derive(Component, Default)]
/// struct Mana {
/// max: u32,
/// current: u32,
/// }
///
/// fn level_up_system(mut commands: Commands, player: Res<PlayerEntity>) {
/// // If a component already exists then modify it, otherwise insert a default value
/// 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));
///
/// // Add a default value if none exists, and then modify the existing or new value
/// commands
/// .entity(player.entity)
/// .entry::<Mana>()
/// .or_default()
/// .and_modify(|mut mana| {
/// mana.max += 10;
/// mana.current = mana.max;
/// });
/// }
///
/// # bevy_ecs::system::assert_is_system(level_up_system);
/// ```
pub fn entry<T: Component>(&mut self) -> EntityEntryCommands<T> {
Expand Down