···3131For some effects it makes sense to allow stacking, so a single entity could be effected multiple times at once.
3232For others, each effect should only be applied once.
33333434-Both behaviours are supported, and can be selected using an effect's `MergeMode`.
3434+Both behaviours are supported, and can be selected using an effect's `MergeMode`. Effects are consider the same if the entities have the same name.
35353636| Mode | Behaviour |
3737|--------|-----------------------------------------------------------------------------------------|
···6464}
6565```
66666767+### Timers
6868+6769### Examples
6868-69707071### Bevy Version Compatibility
7172
+8-6
examples/immediate_stats/decaying_speed.rs
···49495050 commands.entity(*target).with_effect(EffectBundle {
5151 mode: EffectMode::Insert, // Block having multiple of effect stacked on a single target.
5252- lifetime: Some(Lifetime::from_seconds(2.0)), // The duration of the effect.
5353- bundle: DecayingSpeed {
5454- start_speed_boost: Modifier {
5555- bonus: 10,
5656- multiplier: 2.0,
5252+ bundle: (
5353+ Lifetime::from_seconds(2.0), // The duration of the effect.
5454+ DecayingSpeed {
5555+ start_speed_boost: Modifier {
5656+ bonus: 10,
5757+ multiplier: 2.0,
5858+ },
5759 },
5858- },
6060+ ),
5961 ..default()
6062 });
6163}
···52525353 commands.entity(*target).with_effect(EffectBundle {
5454 mode: EffectMode::Insert, // Block having multiple of effect stacked on a single target.
5555- lifetime: Some(Lifetime::from_seconds(2.0)), // The duration of the effect.
5656- bundle: DecayingSpeed {
5757- start_speed_boost: Modifier {
5858- bonus: 10,
5959- multiplier: 2.0,
5555+ bundle: (
5656+ Lifetime::from_seconds(2.0), // The duration of the effect.
5757+ DecayingSpeed {
5858+ start_speed_boost: Modifier {
5959+ bonus: 10,
6060+ multiplier: 2.0,
6161+ },
6062 },
6161- },
6363+ ),
6264 ..default()
6365 });
6466}
+5-3
examples/poison.rs
···4242 }
43434444 commands.entity(*target).with_effect(EffectBundle {
4545- lifetime: Some(Lifetime::from_seconds(4.0)), // The duration of the effect.
4646- delay: Some(Delay::from_seconds(1.0)), // The time between damage ticks.
4747- bundle: Poison { damage: 1 }, // The amount of damage to apply per tick.
4545+ bundle: (
4646+ Lifetime::from_seconds(4.0), // The duration of the effect.
4747+ Delay::from_seconds(1.0), // The time between damage ticks.
4848+ Poison { damage: 1 }, // The amount of damage to apply per tick.
4949+ ),
4850 ..default()
4951 });
5052}
+1-6
src/bundle.rs
···11-use crate::{Delay, EffectMode, Lifetime};
11+use crate::EffectMode;
22use bevy_ecs::prelude::*;
3344/// A "bundle" of components/settings used when applying an effect.
···1919 pub name: Name,
2020 /// Describes the logic used when new effect collides with an existing one.
2121 pub mode: EffectMode,
2222- /// The duration of the effect.
2323- #[doc(alias = "duration")]
2424- pub lifetime: Option<Lifetime>,
2525- /// Repeating timer used for the delay between effect applications.
2626- pub delay: Option<Delay>,
2722 /// Components that will be added to the effect. This is where the actual effect components get added.
2823 pub bundle: B,
2924}
-8
src/command.rs
···3535 self.bundle.mode,
3636 self.bundle.bundle,
3737 ));
3838-3939- if let Some(lifetime) = self.bundle.lifetime {
4040- entity.insert(lifetime);
4141- }
4242-4343- if let Some(delay) = self.bundle.delay {
4444- entity.insert(delay);
4545- }
4638 }
47394840 /// Inserts into the existing entity, and then merges the old effect into it using [`EffectMergeRegistry`].