File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
crates/bevy_ecs/src/system/commands Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1273,15 +1273,32 @@ impl<'a> EntityCommands<'a> {
1273
1273
/// #[derive(Component)]
1274
1274
/// struct Level(u32);
1275
1275
///
1276
+ ///
1277
+ /// #[derive(Component, Default)]
1278
+ /// struct Mana {
1279
+ /// max: u32,
1280
+ /// current: u32,
1281
+ /// }
1282
+ ///
1276
1283
/// fn level_up_system(mut commands: Commands, player: Res<PlayerEntity>) {
1284
+ /// // If a component already exists then modify it, otherwise insert a default value
1277
1285
/// commands
1278
1286
/// .entity(player.entity)
1279
1287
/// .entry::<Level>()
1280
- /// // Modify the component if it exists.
1281
1288
/// .and_modify(|mut lvl| lvl.0 += 1)
1282
- /// // Otherwise, insert a default value.
1283
1289
/// .or_insert(Level(0));
1290
+ ///
1291
+ /// // Add a default value if none exists, and then modify the existing or new value
1292
+ /// commands
1293
+ /// .entity(player.entity)
1294
+ /// .entry::<Mana>()
1295
+ /// .or_default()
1296
+ /// .and_modify(|mut mana| {
1297
+ /// mana.max += 10;
1298
+ /// mana.current = mana.max;
1299
+ /// });
1284
1300
/// }
1301
+ ///
1285
1302
/// # bevy_ecs::system::assert_is_system(level_up_system);
1286
1303
/// ```
1287
1304
pub fn entry < T : Component > ( & mut self ) -> EntityEntryCommands < T > {
You can’t perform that action at this time.
0 commit comments