-
I'm trying out observer, but the behavior seems strange, and I'm wondering when the On Bundle property of this will work? I checked the documentation, but it made me even more confused. https://bevy.org/news/bevy-0-17/#component-lifecycle-events The docs says but why They are both EntityEvent + Component. My code snippet is as follows #[derive(EntityEvent)]
struct GroundClick {
entity: Entity,
} fn on_click_add_point(
mut commands: Commands,
ground: Single<Entity, With<Ground>>,
mouse_input: Res<ButtonInput<MouseButton>>,
) {
if !mouse_input.just_pressed(MouseButton::Left) {
return;
}
info!("test test 1");
let entity = *ground;
commands.trigger(GroundClick { entity });
} impl Plugin for DrawRoadPlugin {
fn build(&self, app: &mut App) {
app
.add_systems(Update, on_click_add_point)
.add_observer(
// won't run
|ground_click: On<GroundClick,Ground>| {
info!("test test2");
},
)
.add_observer(
// can run
|ground_click: On<GroundClick>| {
info!("test test3");
},
);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is because You can sort of fix this by using:
To trigger it, you then need to use |
Beta Was this translation helpful? Give feedback.
This is because
Add
uses anEntityComponentTrigger
, whereas yourGroundClick
event uses anEntityTrigger
.You can sort of fix this by using:
To trigger it, you then need to use
Commands::trigger_with
, and then pass anEntityComponentsTrigger
with the appropriate component ID(s).