Mouse Picking and Mesh2d not working #19319
-
I am trying to get mouse interactions with a Mesh2d using picking. As a test case I'm spawning an entity with a When I run my app and click on the mesh nothing happens. I've been looking at the examples and I can't see what I'm doing differently, could someone show me my mistake? I'm using Bevy 0.16.0, full code: use bevy::color::palettes::css::YELLOW;
use bevy::prelude::*;
fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins);
app.add_systems(Startup, setup);
app.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
let mesh = meshes.add(Circle::new(50.0));
let material = materials.add(Color::Srgba(YELLOW));
commands
.spawn((
Name::new("My Circle"),
Mesh2d(mesh),
MeshMaterial2d(material),
Pickable::default(),
))
.observe(click_observer);
commands.spawn(Camera2d);
}
fn click_observer(interaction: Trigger<Pointer<Click>>, query: Query<&Name>) {
let Ok(name) = query.get(interaction.target()) else {
debug!("failed to get Name component for {}", interaction.target());
return;
};
debug!("Clicked on: {}", name);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Mesh picking plugin is not part of the default plugins, so you need to add the plugin yourself. bevy/examples/picking/mesh_picking.rs Lines 28 to 29 in e9418b3 |
Beta Was this translation helpful? Give feedback.
Mesh picking plugin is not part of the default plugins, so you need to add the plugin yourself.
bevy/examples/picking/mesh_picking.rs
Lines 28 to 29 in e9418b3