Mocked user inputs are never just_pressed or just_released
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## Bevy version
0.6
## What you did
Wrote an integration test that mocks user input, triggering on a just_pressed input.
An input was sent by fetching the `Input` resource, then calling `.press` outside of the app loop.
See full reproduction from #3839 [here](https://github.com/bevyengine/bevy/blob/2521be2dd0d962d408d786d6fbb89293a82e106e/tests/integration_testing.rs#L176).
## What you expected to happen
The input would be `just_pressed`.
## What actually happened
The input is pressed, but not just_pressed.
## Additional information
This occurs due to the call to `input.clear()` in [keyboard_input_system](https://github.com/bevyengine/bevy/blob/main/crates/bevy_input/src/keyboard.rs#L14), which resets the just_pressed and just_released events.
The workaround for this is to send the very onerous raw events used by these systems: e.g. `KeyboardInput`.
## Potential fixes
1. We could swap to a `Duration` based model for just_pressed / just_released, like I did in [`leafwing-input-manager`](https://github.com/Leafwing-Studios/leafwing-input-manager/blob/13dbe6af4551b23a03afee2d50ac9b060db93c07/src/action_state.rs#L14). This is useful for gameplay and sophisticated user input processing reasons, but a bit more expensive.
2. We could write special-cased input mocking tools that workaround this (see [my version](https://github.com/Leafwing-Studios/leafwing-input-manager/blob/dev/src/input_mocking.rs)), which would be useful, but leave the footgun in place for users attempting to mock or otherwise modify input in this way.
3. We could clear just-pressed / just-released at the end of the schedule, instead of in the method fetches the new inputs. This should be much more robust, but introduces an extra system call.
IMO 1 and 3 are viable, 2 is not.
Contributor guide
Research direction
Start with the reproduction in tests/integration_testing.rs around the linked example and read crates/bevy_input/src/keyboard.rs, especially keyboard_input_system and its input.clear() call. Compare the documented potential fixes and verify that mocked presses produce just_pressed and just_released reliably without breaking the existing input flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100