Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
BorisBoutillier opened this issue Sep 21, 2020 · 0 comments · Fixed by #543
Closed

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

BorisBoutillier opened this issue Sep 21, 2020 · 0 comments · Fixed by #543
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior

Comments

@BorisBoutillier
Copy link
Contributor

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
    );
}
@Moxinilian Moxinilian added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events labels Sep 21, 2020
@cart cart closed this as completed in #543 Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants