Skip to content

Duplicated components are not detected using Added query #1443

@atbentley

Description

@atbentley

Bevy version

0.4.0

Operating system & version

macOS 11.2.1

What you did

use bevy::prelude::*;

struct Bananas {
    bananas: String
}

fn init(commands: &mut Commands) {
    commands.spawn((Bananas { bananas: String::from("🍌") }, ));

    commands.spawn((Bananas { bananas: String::from("this banana is overwritten") }, ))
        .with(Bananas { bananas: String::from("this banana isn't change detected") });
}

fn changed_bananas(query: Query<&Bananas, Added<Bananas>>) {
    for bananas in query.iter() {
        info!("added query banana: {}", bananas.bananas);
    }
}

fn all_bananas(query: Query<&Bananas>) {
    for bananas in query.iter() {
        info!("normal query banana: {}", bananas.bananas);
    }
}

#[bevy_main]
fn main() {
    App::build()
        .add_plugin(bevy::log::LogPlugin)
        .add_startup_system(init.system())
        .add_system(changed_bananas.system())
        .add_system(all_bananas.system())
        .run();
}

What you expected to happen

The following output should be produced

normal query banana: 🍌
added query banana: 🍌
normal query banana: this banana isn't change detected
added query banana: this banana isn't change detected

What actually happened

normal query banana: 🍌
added query banana: 🍌
normal query banana: this banana isn't change detected

Additional information

Adding a duplicated component using spawn().with() produces this behaviour.

So does adding a duplicated component using spawn().insert_one().

Adding a duplicated component using spawn((Banana {}, Banana{})) throws an error.

Possibly related issue: #333

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