Skip to content

PickingInteraction randomly switch to None even when hovered #19465

Open
@djeedai

Description

@djeedai

Bevy version

0.16

What you did

/// Workaround for #19464 change detection broken on [`PickingInteraction`].
#[derive(Component)]
struct PrevPickingInteraction(pub PickingInteraction);

fn save_prev_picking_interaction(
    mut query: Query<(Entity, &PickingInteraction, &mut PrevPickingInteraction)>,
) {
    for (e, pi, mut ppi) in &mut query {
        trace!("hover: e={:?} prev={:?} cur={:?}", e, ppi.0, *pi);
        ppi.0 = *pi;
    }
}

app.add_systems(First, save_prev_picking_interaction);

What went wrong

The target Mesh2d is a large-ish rectangle, so there's no change the mouse accidentally leaves it. When slightly moving the mouse around a few pixels, I randomly get a None for 1 frame, immediately followed by a Hovered again. This looks like a race condition or timing issue where 1 frame would be skipped for example, and would not detect the mouse temporarily. I'm already working around #19464, and now it seems I also need averaging/smoothing over multiple frames to get a stable hover/non-hover (mouse enter/leave) pair of events. This makes using bevy_picking pretty cumbersome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-PickingPointing at and selecting objects of all sortsC-BugAn unexpected or incorrect behaviorC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-ReproductionNeeds an up-to-date or minimal reproductionX-UncontroversialThis work is generally agreed upon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions