Open
Description
Bevy version
main
What you did
Run the following code and try to press some key.
use bevy::{
ecs::entity::Entities,
input::keyboard::KeyboardInput,
input_focus::{FocusedInput, InputDispatchPlugin, InputFocus, set_initial_focus},
prelude::*,
};
fn main() {
App::new()
.add_plugins((DefaultPlugins, InputDispatchPlugin))
.add_systems(PostStartup, setup.after(set_initial_focus))
.add_observer(on_keyboard_input)
.run();
}
fn setup(mut input_focus: ResMut<InputFocus>, mut commands: Commands) {
let entity = commands.spawn_empty().id();
input_focus.0 = Some(entity);
commands.entity(entity).despawn();
}
fn on_keyboard_input(trigger: Trigger<FocusedInput<KeyboardInput>>, entities: &Entities) {
assert!(entities.contains(trigger.target()));
}
What went wrong
It's should not crash. Bevy should check the entity is alive or not. If not the event should be triggered on window entity.
Additional information
None.