Skip to content

Query.removed() is always empty #941

@lukors

Description

@lukors

Bevy version
rev 72b2fc9

Operating system & version
Windows 10

What you did
Here is a simple example:

use bevy::prelude::*;

struct MyComponentOne;
struct MyComponentTwo;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_system(spawn.system())
        .add_system(remove.system())
        .add_system(print.system())
        .run();
}

fn spawn(
    commands: &mut Commands,
) {
    commands.spawn((MyComponentOne, MyComponentTwo));
}

fn remove(
    commands: &mut Commands,
    query: Query<Entity>,
) {
    for entity in query.iter() {
        commands.remove_one::<MyComponentOne>(entity);
    }
}

fn print(
    query: Query<Entity>,
) {
    for thing in query.removed::<MyComponentOne>() {
        println!("{:?}", thing);
    }
}

What you expected to happen
To see something printed in the console.

What actually happened
Nothing is printed.

Additional information
It's been suggested in the Discord that perhaps Query.removed() is not meant to be used in this way. If so, how is it meant to be used? We should add this information to the documentation of the function.

If it's not meant to be used in this way, is there some best practice yet for how to check for removed components in Bevy? This would be great knowledge to have in the community as it's been very hard to find any information about this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions