Skip to content
Discussion options

You must be logged in to vote

You should have something wrong in your code as the behavior of the Added filter is what you expect.

If I cargo test -- --nocapture the following, I got what I expect : only 1 "Added".

[derive(Component)]
struct MyComponent;

#[test]
fn test_added() {
    let mut app = App::new();
    app.add_systems(Update, |q: Query<Entity, Added<MyComponent>>| {
        let mut i = 0;
        for e in &q {
            i += 1;
            eprintln!("Added {e}");
        }
        assert_eq!(1, i);
    });

    let root = app.world_mut().spawn(()).id();
    let child = app.world_mut().spawn(MyComponent).id();
    app.world_mut().entity_mut(root).add_child(child);
    app.update();
}

Output :

Added 1v1
test

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MuongKimhong
Comment options

Answer selected by MuongKimhong
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants