Closed mahulst closed 3 months ago
To add more context, picking doesn't need this, the mod_raycast backend for picking does. If you are using a picking shader as the backend, you would not need the mesh to stay loaded on the CPU.
Thankyou @mahulst for posting here. I have been losing my mind as to why my click event wasn't firing! 🙏 👏
I was using RaycastPickable
as part of my bundle, I am just coming back to this project from a few months prior and bumped versions etc. I'm not sure why I had it originally.
I've removed it now and things work as expected!
I appreciate the answer too Aevyrie, although I'm not 100% clear. I am not sure what I lose by removing the RaycastPickable
.
Also I was confused how I was supposed to add the RenderAssetUsages::all()
to my mesh bundle.
e.g:
// Where does this fit in?
let mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::all());
// This was the previous bundle:
let bundle = MaterialMesh2dBundle {
mesh: meshes.add(Circle::new(radius)).into(),
material: materials.add(ColorMaterial {
color: colour.into(),
texture: None,
}),
transform: *transform,
..default()
}
Not that I need to now I've removed the RaycastPickable!
although I'm not 100% clear. I am not sure what I lose by removing the RaycastPickable.
This is documented:
https://docs.rs/bevy_picking_raycast/0.20.0/bevy_picking_raycast/struct.RaycastPickable.html
You likely inherited this from an old version of the plugin, and did not remove it when it became optional.
Also I was confused how I was supposed to add the RenderAssetUsages::all() to my mesh bundle.
You don't need to worry about this, by default, bevy sets to all
. https://docs.rs/bevy/latest/bevy/render/render_asset/struct.RenderAssetUsages.html#method.default
This issue only applies if you set render usages to render world only.
Issue already resolved, only filing it so others are aware of it if they encounter the same problem.
I added a click handler to a mesh that never fired:
Turns out the mesh created from code and before picking I only needed it to exist while rendering:
Picking does need it in the MAIN_WORLD though, so it should be