Skip to content

QuerySet does not appear to trigger change detection properly #2408

Closed
@alice-i-cecile

Description

@alice-i-cecile

Bevy version

0.5

What you did

From a user's system on Discord:

pub fn check_tasks(
    mut commands: Commands,
    sim_params: Res<SimParams>,
    physical_object_query: Query<&PhysicalObject>,
    physical_object_id_query: Query<Entity, With<PhysicalObject>>,
    mut resource_carrier_query: Query<&mut ResourceCarrier>,
    mut resource_storage_query: Query<(&mut ResourceStorage, Entity)>,
    mut tasks_queries: QuerySet<(Query<&mut TaskQue>, Query<Entity, Changed<TaskQue>>)>,
    mut ev_check_task_event: EventReader<CheckTaskEvent>,
) {
    let creature_ids: Vec<Entity> = tasks_queries
        .q1()
        .iter()
        .chain(
            ev_check_task_event
                .iter()
                .map(|CheckTaskEvent(creature_id)| *creature_id),
        )
        .collect();
    println!("Something was updated for {}", creature_ids.len());

    for creature_id in creature_ids {
        if let Ok(mut task_que_component) = tasks_queries.q0_mut().get_mut(creature_id) {
            if let Some(task) = task_que_component.0.front() {
                println!("Something was updated");
                if try_accomplish_task(
                    &mut commands,
                    &sim_params.world_rect,
                    &physical_object_query,
                    &physical_object_id_query,
                    &mut resource_carrier_query,
                    &mut resource_storage_query,
                    &creature_id,
                    &task,
                ) {
                    task_que_component.0.pop_front();
                    *task_que_component = TaskQue(task_que_component.0.clone());
                    println!("dereferenced");
                }
            }
        }
    }
}

TaskQue contains a standard VecDeque, and the method called is pop_front.

What you expected to happen

The TaskQue component should be marked as changed.

What actually happened

The TaskQue component is not marked as changed.

Additional information

This needs a minimal reproduction still.

        if let Ok(mut task_que_component) = tasks_queries.q0_mut().get_mut(creature_id) {

I think that QuerySet is the most likely candidate, but get_mut may be responsible instead.

Even if pop_front doesn't trigger change detection, setting an entirely new value certainly should.

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions