···11# Bevy Alchemy
2233-An experimental, status effects-as-entities system for Bevy.33+[](https://crates.io/crates/bevy_alchemy)
44+[](https://docs.rs/bevy_alchemy)
55+
66+77+An experimental, status effects-as-entities system for Bevy.
88+99+### Applying Effects
1010+Effects can be applied using `with_effect` or `with_effects` (similar to `with_child` and `with_children` respectively).
1111+```rust ignore
1212+commands.entity(target).with_effect(EffectBundle {
1313+ name: Name::new("Effect"),
1414+ bundle: MyEffect,
1515+ ..default()
1616+});
1717+```
1818+They can also be added using spawn-style syntax.
1919+```rust ignore
2020+commands.spawn((
2121+ Name::new("Target"),
2222+ EffectedBy::spawn(EffectBundle {
2323+ name: Name::new("Effect"),
2424+ bundle: MyEffect,
2525+ ..default()
2626+ }),
2727+));
2828+```
2929+3030+### Effect Modes
3131+For some effects it makes sense to allow stacking, so a single entity could be effected multiple times at once.
3232+For others, each effect should only be applied once.
3333+3434+Both behaviours are supported, and can be selected using an effect's `MergeMode`.
3535+3636+| Mode | Behaviour |
3737+|--------|-----------------------------------------------------------------------------------------|
3838+| Stack | Multiple of the same effect can exist at once. |
3939+| Insert | New applications will overwrite the existing one. |
4040+| Merge | New applications are merged with the existing one, using a configurable merge function. |
4141+4242+### Implementing Effects
4343+Effects can be implemented using simple systems. Below is an excerpt from the poison example.
4444+```rust ignore
4545+/// Runs every frame and deals the poison damage.
4646+fn deal_poison_damage(
4747+ effects: Query<(&Effecting, &Delay, &Poison)>,
4848+ mut targets: Query<&mut Health>,
4949+) {
5050+ for (target, delay, poison) in effects {
5151+ // We wait until the delay finishes to apply the damage.
5252+ if !delay.timer.is_finished() {
5353+ continue;
5454+ }
5555+5656+ // Skip if the target doesn't have health.
5757+ let Ok(mut health) = targets.get_mut(target.0) else {
5858+ continue;
5959+ };
6060+6161+ // Otherwise, deal the damage.
6262+ health.0 -= poison.damage;
6363+ }
6464+}
6565+```
6666+6767+### Examples
6868+6969+7070+### Bevy Version Compatibility
7171+7272+| Bevy | Bevy Alchemy |
7373+|--------|--------------|
7474+| `0.17` | `0.1` |