Skip to content

dispatch_focused_input not checking whether the focused entity is alive or not. #20057

Open
@notmd

Description

@notmd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-InputPlayer input via keyboard, mouse, gamepad, and moreC-BugAn unexpected or incorrect behaviorD-StraightforwardSimple bug fixes and API improvements, docs, test and examples

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions