Skip to content

Commit d4e3fcd

Browse files
committed
Fix incorrect behavior of just_pressed and just_released in Input<GamepadButton> (#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
1 parent addc36f commit d4e3fcd

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

crates/bevy_input/src/gamepad.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ pub fn gamepad_connection_system(
992992
mut button_axis: ResMut<Axis<GamepadButton>>,
993993
mut button_input: ResMut<Input<GamepadButton>>,
994994
) {
995-
button_input.bypass_change_detection().clear();
996995
for connection_event in connection_events.iter() {
997996
let gamepad = connection_event.gamepad;
998997

@@ -1117,27 +1116,24 @@ impl GamepadButtonChangedEvent {
11171116
}
11181117
}
11191118

1120-
/// Uses [`GamepadAxisChangedEvent`]s to update update the relevant `Input` and `Axis` values.
1119+
/// Uses [`GamepadAxisChangedEvent`]s to update the relevant `Input` and `Axis` values.
11211120
pub fn gamepad_axis_event_system(
1122-
mut button_input: ResMut<Input<GamepadButton>>,
11231121
mut gamepad_axis: ResMut<Axis<GamepadAxis>>,
11241122
mut axis_events: EventReader<GamepadAxisChangedEvent>,
11251123
) {
1126-
button_input.bypass_change_detection().clear();
11271124
for axis_event in axis_events.iter() {
11281125
let axis = GamepadAxis::new(axis_event.gamepad, axis_event.axis_type);
11291126
gamepad_axis.set(axis, axis_event.value);
11301127
}
11311128
}
11321129

1133-
/// Uses [`GamepadButtonChangedEvent`]s to update update the relevant `Input` and `Axis` values.
1130+
/// Uses [`GamepadButtonChangedEvent`]s to update the relevant `Input` and `Axis` values.
11341131
pub fn gamepad_button_event_system(
11351132
mut button_events: EventReader<GamepadButtonChangedEvent>,
11361133
mut button_input: ResMut<Input<GamepadButton>>,
11371134
mut button_axis: ResMut<Axis<GamepadButton>>,
11381135
settings: Res<GamepadSettings>,
11391136
) {
1140-
button_input.bypass_change_detection().clear();
11411137
for button_event in button_events.iter() {
11421138
let button = GamepadButton::new(button_event.gamepad, button_event.button_type);
11431139
let value = button_event.value;
@@ -1197,7 +1193,9 @@ pub fn gamepad_event_system(
11971193
mut connection_events: EventWriter<GamepadConnectionEvent>,
11981194
mut button_events: EventWriter<GamepadButtonChangedEvent>,
11991195
mut axis_events: EventWriter<GamepadAxisChangedEvent>,
1196+
mut button_input: ResMut<Input<GamepadButton>>,
12001197
) {
1198+
button_input.bypass_change_detection().clear();
12011199
for gamepad_event in gamepad_events.iter() {
12021200
match gamepad_event {
12031201
GamepadEvent::Connection(connection_event) => {

0 commit comments

Comments
 (0)