Skip to content

Commit

Permalink
Fix incorrect behavior of just_pressed and just_released in `Inpu…
Browse files Browse the repository at this point in the history
…t<GamepadButton>` (bevyengine#7238)

# Objective

- Fixes a bug where `just_pressed` and `just_released` in `Input<GamepadButton>` might behave incorrectly due calling `clear` 3 times in a single frame through these three different systems: `gamepad_button_event_system`, `gamepad_axis_event_system` and `gamepad_connection_system` in any order

## Solution

- Call `clear` only once and before all the above three systems, i.e. in `gamepad_event_system`

## Additional Info

- Discussion in Discord: https://discord.com/channels/691052431525675048/768253008416342076/1064621963693273279
  • Loading branch information
elbertronnie authored and ItsDoot committed Feb 1, 2023
1 parent 6904654 commit 41b75af
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions crates/bevy_input/src/gamepad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,6 @@ pub fn gamepad_connection_system(
mut button_axis: ResMut<Axis<GamepadButton>>,
mut button_input: ResMut<Input<GamepadButton>>,
) {
button_input.bypass_change_detection().clear();
for connection_event in connection_events.iter() {
let gamepad = connection_event.gamepad;

Expand Down Expand Up @@ -1117,27 +1116,24 @@ impl GamepadButtonChangedEvent {
}
}

/// Uses [`GamepadAxisChangedEvent`]s to update update the relevant `Input` and `Axis` values.
/// Uses [`GamepadAxisChangedEvent`]s to update the relevant `Input` and `Axis` values.
pub fn gamepad_axis_event_system(
mut button_input: ResMut<Input<GamepadButton>>,
mut gamepad_axis: ResMut<Axis<GamepadAxis>>,
mut axis_events: EventReader<GamepadAxisChangedEvent>,
) {
button_input.bypass_change_detection().clear();
for axis_event in axis_events.iter() {
let axis = GamepadAxis::new(axis_event.gamepad, axis_event.axis_type);
gamepad_axis.set(axis, axis_event.value);
}
}

/// Uses [`GamepadButtonChangedEvent`]s to update update the relevant `Input` and `Axis` values.
/// Uses [`GamepadButtonChangedEvent`]s to update the relevant `Input` and `Axis` values.
pub fn gamepad_button_event_system(
mut button_events: EventReader<GamepadButtonChangedEvent>,
mut button_input: ResMut<Input<GamepadButton>>,
mut button_axis: ResMut<Axis<GamepadButton>>,
settings: Res<GamepadSettings>,
) {
button_input.bypass_change_detection().clear();
for button_event in button_events.iter() {
let button = GamepadButton::new(button_event.gamepad, button_event.button_type);
let value = button_event.value;
Expand Down Expand Up @@ -1197,7 +1193,9 @@ pub fn gamepad_event_system(
mut connection_events: EventWriter<GamepadConnectionEvent>,
mut button_events: EventWriter<GamepadButtonChangedEvent>,
mut axis_events: EventWriter<GamepadAxisChangedEvent>,
mut button_input: ResMut<Input<GamepadButton>>,
) {
button_input.bypass_change_detection().clear();
for gamepad_event in gamepad_events.iter() {
match gamepad_event {
GamepadEvent::Connection(connection_event) => {
Expand Down

0 comments on commit 41b75af

Please sign in to comment.