Bevy version
- Bevy 0.15.2
- Also tested on main at commit 45c2666
What you did
- Create an observer for
OnReplace or OnRemove some component A
- Create another observer for
OnReplace or OnRemove some component B
- Spawn an entity with some component A
- Remove the bundle
(A, B) from that entity
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, spawn_stuff)
.add_observer(observe_remove_a)
.add_observer(observe_remove_b)
.run();
}
fn spawn_stuff(mut commands: Commands) {
let e = commands.spawn(A).id();
commands.entity(e).remove::<(A, B)>();
}
#[derive(Component)]
struct A;
#[derive(Component)]
struct B;
fn observe_remove_a(trigger: Trigger<OnRemove, A>) {
info!("Removed A");
}
fn observe_remove_b(trigger: Trigger<OnRemove, B>) {
info!("Removed B");
}
What went wrong
Both observers are triggered, even though the entity has no component B.
This only happens if you are observing the same trigger for another component in the bundle that matches. So in the above example, removing observe_remove_a does not result in observe_remove_b triggering. Or changing observe_remove_b to be OnReplace also doesn't make observe_remove_b trigger.
Bevy version
What you did
OnReplaceorOnRemovesome component AOnReplaceorOnRemovesome component B(A, B)from that entityWhat went wrong
Both observers are triggered, even though the entity has no component
B.This only happens if you are observing the same trigger for another component in the bundle that matches. So in the above example, removing
observe_remove_adoes not result inobserve_remove_btriggering. Or changingobserve_remove_bto beOnReplacealso doesn't makeobserve_remove_btrigger.