Skip to content

mesh_picking not updating when mesh data changes, bug or intended? #18221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ncorbin786 opened this issue Mar 10, 2025 · 4 comments
Open

mesh_picking not updating when mesh data changes, bug or intended? #18221

ncorbin786 opened this issue Mar 10, 2025 · 4 comments
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Picking Pointing at and selecting objects of all sorts C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@ncorbin786
Copy link

Bevy version

0.15.3

What you did

Might be a bug with mesh_picking. I noticed that when I adjusted the vertex positions on a Plane3d in real time the Trigger<Pointer<Click>> events would still fire, but only based on the dimensions of the initial mesh.

The updates I made to the Mesh3d vertex positions wouldn't affect it. Visually I could see the new mesh was larger, but if I clicked anywhere in those zones nothing happened. I had to click the original position to get it to fire.

I was using mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, new_positions.clone()); to adjust the vertex positions.

What went wrong

  • Adjusting Mesh3d vertex positions does not update mesh_picking

Additional information

I found I was able to get it to work, as intended, after updating the vertex position by removing the Aabb component and re-adding it:

                    // Update the AABB to refresh raycasting
                    commands.entity(parent.get()).remove::<Aabb>();
                    commands.entity(parent.get()).insert(mesh.compute_aabb().unwrap());
@ncorbin786 ncorbin786 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 10, 2025
@alice-i-cecile alice-i-cecile added A-Picking Pointing at and selecting objects of all sorts A-Assets Load files from disk to use for things like images, models, and sounds and removed S-Needs-Triage This issue needs to be labelled labels Mar 10, 2025
@alice-i-cecile
Copy link
Member

This is a bug. We need to be using asset changed detection. There's a new system param for it.

@alice-i-cecile alice-i-cecile added S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Mar 10, 2025
@notmd
Copy link
Contributor

notmd commented Mar 10, 2025

Related #7971

@StudioLE
Copy link

StudioLE commented Mar 23, 2025

This has been bugging me for a while as well. It also occurs if you replace the Mesh3d with a new Mesh

Manually re-computing the Aabb does fix it.

Condensed workaround:

    /// Update the mesh geometry when the spline changes.
    fn on_spline_changed(
        mut events: EventReader<SplineChanged>,
        mut surfaces: Query<(&mut Mesh3d, &mut Aabb)>,
        mut meshes: ResMut<Assets<Mesh>>,
    ) {
        for event in events.read() {
            for (mut mesh_3d, mut aabb) in &mut surfaces {
                let mesh: Mesh = create_mesh();
                *aabb = mesh.compute_aabb().expect("Should be able to compute AABB");
                *mesh_3d = Mesh3d(meshes.add(mesh));
            }
        }
    }

@alice-i-cecile
Copy link
Member

Ah, so the same bug that we're getting with animated meshes and their AABB: #4971.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Picking Pointing at and selecting objects of all sorts C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

No branches or pull requests

4 participants