Skip to content

Added<X> not properly filtered in QueryOne.get() and Query.get() methods #541

@BorisBoutillier

Description

@BorisBoutillier

With the following standalone testcase, after the second iteration when Added counting becomes 0, I think we should also see both boolean be false.
The second boolean, being based QueryOne.get() has been reported by @cart to behave incorrectly in #488.
But I suspect the first one, based onQuery.get() should also return false ?

use bevy::prelude::*;

fn main() {
    App::build()
        .add_default_plugins()
        .add_startup_system(startup_system.system())
        .add_system(normal_system.system())
        .run();
}

struct Comp {}
/// Startup systems are run exactly once when the app starts up.
/// They run right before "normal" systems run.
fn startup_system(mut commands: Commands) {
    commands.spawn((Comp {},));
    let entity = commands.current_entity().unwrap();
    commands.insert_resource(entity);
}

fn normal_system(
    entity: Res<Entity>,
    mut query: Query<(&Comp,)>,
    mut query_added: Query<(Added<Comp>,)>,
) {
    let mut n_comp = 0;
    let mut n_added = 0;
    for (_comp,) in &mut query.iter() {
        n_comp += 1;
    }
    for (_comp,) in &mut query_added.iter() {
        n_added += 1;
    }
    let found1 = query_added.get::<Comp>(*entity).is_some();
    let mut one = query_added.entity(*entity).unwrap();
    let found2 = one.get().is_some();
    println!(
        "Count: {}, Added: {}, query.get {} query.entity.get {}",
        n_comp, n_added, found1, found2
    );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions