-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Mutating a component with insert(_one) doesn't trigger Mutated query filter #333
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior
Description
Expected Behavior
I tried to make a small example and it should print "Tag added" once because the system with Added filter should be called once.
Or maybe I'm wrong and there is another way to add a component to an entity.
Actual Behavior
"Tag added" is never printed meaning the print_added function is never called.
Steps to Reproduce the Problem
- Write a system inserting a component into an entity with insert_one or insert
- Write a system using one of the three filter with the previous component
- This system will not work as intented
Specifications
- Version: 0.1.3 rev=#f7131509b94b3f70eb29be092d4fd82971f547fa
- Platform: Linux (Manjaro)
Example
use bevy::prelude::*;
fn main() {
App::build()
.add_default_plugins()
.add_resource(PrintTimer(Timer::from_seconds(3.0, true)))
.add_startup_system(setup.system())
.add_system(add_tag_on_click.system())
.add_system(print_added.system())
.add_system(print_timed.system())
.run();
}
fn setup(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
commands
.spawn(UiCameraComponents::default())
.spawn(ButtonComponents {
material: materials.add(Color::RED.into()),
style: Style {
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
..Default::default()
},
..Default::default()
});
}
struct Tag;
fn add_tag_on_click(mut commands: Commands, mut query: Query<(Mutated<Interaction>, Entity)>) {
for (interaction, entity) in &mut query.iter() {
if let Interaction::Clicked = *interaction {
println!("Click on {:?}", entity);
commands.insert_one(entity, Tag);
println!("Tag inserted");
}
}
}
fn print_added(_: Added<Tag>) {
println!("Tag added");
}
struct PrintTimer(Timer);
fn print_timed(time: Res<Time>, mut timer: ResMut<PrintTimer>, mut query: Query<&Tag>) {
timer.0.tick(time.delta_seconds);
if timer.0.finished {
for (i, _) in &mut query.iter().iter().enumerate() {
println!("I'm Tag #{}", i);
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior