diff --git a/crates/bevy_gilrs/src/gilrs_system.rs b/crates/bevy_gilrs/src/gilrs_system.rs index de1d0afb3c733..553192810381c 100644 --- a/crates/bevy_gilrs/src/gilrs_system.rs +++ b/crates/bevy_gilrs/src/gilrs_system.rs @@ -1,6 +1,6 @@ use crate::converter::{convert_axis, convert_button, convert_gamepad_id}; use bevy_ecs::event::EventWriter; -use bevy_ecs::system::{NonSend, NonSendMut, Res}; +use bevy_ecs::system::{NonSend, NonSendMut, Res, ResMut}; use bevy_input::gamepad::{ GamepadAxisChangedEvent, GamepadButtonChangedEvent, GamepadConnection, GamepadConnectionEvent, GamepadSettings, @@ -29,8 +29,8 @@ pub fn gilrs_event_startup_system( pub fn gilrs_event_system( mut gilrs: NonSendMut, mut events: EventWriter, + mut gamepad_buttons: ResMut>, gamepad_axis: Res>, - gamepad_buttons: Res>, gamepad_settings: Res, ) { while let Some(gilrs_event) = gilrs @@ -65,6 +65,9 @@ pub fn gilrs_event_system( GamepadButtonChangedEvent::new(gamepad, button_type, filtered_value) .into(), ); + // Update the current value prematurely so that `old_value` is correct in + // future iterations of the loop. + gamepad_buttons.set(button, filtered_value); } } } diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index e81c075b759a9..6948d7e6286a3 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -1133,7 +1133,6 @@ pub fn gamepad_axis_event_system( pub fn gamepad_button_event_system( mut button_events: EventReader, mut button_input: ResMut>, - mut button_axis: ResMut>, settings: Res, ) { for button_event in button_events.iter() { @@ -1148,8 +1147,6 @@ pub fn gamepad_button_event_system( } else if button_property.is_pressed(value) { button_input.press(button); }; - - button_axis.set(button, value); } }