Skip to content

Ability to disable "missed events" warnings for specific EventReaders #6173

Closed
@rmemr

Description

@rmemr

What problem does this solve or what need does it fill?

#5730 introduced warning messages for missed events in EventReaders. However a combination of state dependent systems and events which are triggered in other states (e.g. by mouse input) will produce the warnings upon entering the state because the EventReader from the state dependent system will lag behind.

As far as I can see there is currently no obvious simple workaround for this.

The following example illustrates the problem: a user using the mouse wheel will trigger the warning on the next state change.

use bevy::{prelude::*, input::mouse::MouseWheel};

#[derive(Hash, PartialEq, Eq, Debug, Clone)]
enum StateTest {
    StateA,
    StateB,
}

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_state(StateTest::StateA)
        .add_system(hotkeys)
        .add_system_set(SystemSet::on_update(StateTest::StateA).with_system(state_a_system))
        .add_system_set(SystemSet::on_update(StateTest::StateB).with_system(state_b_system))
        .run();
}

fn hotkeys(keys: Res<Input<KeyCode>>, mut app_state: ResMut<State<StateTest>>) {
    for key in keys.get_just_pressed() {
        if matches!(key, KeyCode::Space) {
            match app_state.current() {
                StateTest::StateA => {
                    warn!("state A -> State B");
                    app_state.overwrite_set(StateTest::StateB).unwrap();
                }
                StateTest::StateB => {
                    warn!("state B -> State A");
                    app_state.overwrite_set(StateTest::StateA).unwrap();
                }
            }
        }
    }
}

fn state_a_system(mut mouse_wheel: EventReader<MouseWheel>) {
    for _ in mouse_wheel.iter() {
        // do something
    }
}

fn state_b_system(mut mouse_wheel: EventReader<MouseWheel>) {
    for _ in mouse_wheel.iter() {
        // do something
    }
}

What solution would you like?

I don't have a preferred solution.

Since the general availability of this warning seems like a useful addition maybe a conditional flag/method to disable this warning for specific EventReaders.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions