bevyengine / bevyengine/bevy

Mesh picking plugin sometimes spams `Pointer<Out>` events infinitely for a stationary mouse

Open
#19,181 3 comments 0 reactions 0 assignees View on GitHub
A-Picking C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.16

## What you did

```rust
use bevy::{
color::palettes::css::{BLUE, GREEN, RED},
prelude::*,
};

fn main() {
App::new()
.add_plugins((DefaultPlugins, MeshPickingPlugin))
.add_systems(Startup, setup)
.add_observer(|trigger: Trigger>, names: Query<&Name>| {
info!("POINTER OUT EVENT");
info!(
"trigger.event().target: {:?} ({:?})",
trigger.event().target,
names.get(trigger.event().target)
);
info!(
"trigger.target(): {:?} ({:?}",
trigger.target(),
names.get(trigger.target())
);
})
.run();
}

fn setup(
mut commands: Commands,
mut meshes: ResMut>,
mut materials: ResMut>,
) {
commands.spawn((
Name::new("Scene"),
Transform::IDENTITY,
Visibility::Visible,
children![
hover_test_object(vec2(-150.0, 0.0), &mut meshes, &mut materials),
hover_test_object(vec2(-50.0, 0.0), &mut meshes, &mut materials),
hover_test_object(vec2(50.0, 0.0), &mut meshes, &mut materials),
hover_test_object(vec2(150.0, 0.0), &mut meshes, &mut materials),
],
));
commands.spawn((Name::new("Camera"), Camera2d));
}

pub fn hover_test_object(
pos: Vec2,
meshes: &mut ResMut>,
materials: &mut ResMut>,
) -> impl Bundle {
(
Name::new("Hover Test"),
Mesh2d(meshes.add(Rectangle::from_length(50.0))),
MeshMaterial2d(materials.add(Color::WHITE)),
Transform::from_xyz(pos.x, pos.y, 0.0),
children![
(
decoration(Color::from(GREEN), meshes, materials),
Transform::from_rotation(Quat::from_rotation_z(45_f32.to_radians()))
),
(
decoration(Color::from(BLUE), meshes, materials),
Transform::from_rotation(Quat::from_rotation_z(90_f32.to_radians()))
),
(
decoration(Color::from(RED), meshes, materials),
Transform::from_rotation(Quat::from_rotation_z(135_f32.to_radians()))
)
],
)
}

pub fn decoration(
color: Color,
meshes: &mut ResMut>,
materials: &mut ResMut>,
) -> impl Bundle {
(
Name::new("Decoration"),
Mesh2d(meshes.add(Rectangle::new(44.0, 32.0))),
MeshMaterial2d(materials.add(Color::WHITE)),
children![(
Name::new("Decoration Inner"),
Mesh2d(meshes.add(Rectangle::new(44.0, 30.0))),
MeshMaterial2d(materials.add(color)),
Transform::from_xyz(0.0, 0.0, 0.1),
)],
)
}
```

## What went wrong

Log gets spammed with `Pointer` events even when the mouse isn't moving

## Additional Information

This caused major issues for me when working on a game jam entry. I think it's related to Z-fighting, but the object is visually stable despite the erratic behavior from the picking plugin

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Bevy 0.16 reproduction with MeshPickingPlugin and observe Pointer events while the mouse is stationary. Trace the mesh picking and Pointer event handling from the MeshPickingPlugin entry point, including the overlapping child meshes. Done means a stationary pointer does not produce an unbounded stream of Pointer events, while pointer transitions still emit the expected events.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.