Skip to content

All observers triggered when any element of a bundle is removed. #17897

Description

@andriyDev

Bevy version

  • Bevy 0.15.2
  • Also tested on main at commit 45c2666

What you did

  1. Create an observer for OnReplace or OnRemove some component A
  2. Create another observer for OnReplace or OnRemove some component B
  3. Spawn an entity with some component A
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions