Leafwing-Studios / leafwing-input-manager

A straightforward stateful input manager for the Bevy game engine.
Apache License 2.0
686 stars 106 forks source link

Setting `ToggleAction<T>` to disabled does not reset input state #506

Closed Veritius closed 1 month ago

Veritius commented 5 months ago

Version

0.13.3

Operating system & version

Linux Mint 21.1 x86_64 (kernel 5.15.0-101-generic)

What you did

I was implementing a 'paused' state for my game, which disables all movement inputs. However, I noticed that occasionally, when pressing the pause button, the player character would drift in a direction. After some testing, I noticed this happened when I flicked my mouse and hit escape at the same time.

This commit is a reproducible example. The pause button is Escape, and the movement inputs are your standard FPS WASD/mouse.

What you expected to happen

Movement inputs to be reset and nothing to occur, as if no buttons were pressed and the mouse wasn't moved.

What actually happened

Input state would stay as it was when ToggleAction<T> was set to Disabled, leading to a constant movement around until the pause button was hit again to unpause the game, which ticked the input state.

Curiously, this only affects axis inputs. Button inputs work fine.

benfrankel commented 5 months ago

This is probably because ActionState::release resets the button state (.state) but not the .axis_pair or .value:

https://github.com/Leafwing-Studios/leafwing-input-manager/blob/29a9458258f93094911df3f82a7f82d7ee263e2e/src/action_state.rs#L383-L394