bevyengine / bevyengine/bevy

Inputs can be missed (or duplicated) when using a fixed time step

Open
#6,183 17 comments 4 reactions 0 assignees View on GitHub
A-ECS A-Input A-Time C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.8.1

## What you did

Create a system that responds to input events inside of a fixed times step.

## What went wrong

Sometimes, input events are missed: `Input::just_pressed` and `just_released` are never picked up.

Other times, they're duplicated: we respond to the same input multiple times.

## Explanation

### Missed inputs

Fixed time step systems may not run every frame, but `Input::just_pressed` and friends is reset every frame (and events are only double buffered). If the frame rate is significantly faster than the time step, the fixed time step schedule will sometimes not run, completely missing the input (which will no longer be just-pressed).

### Duplicated inputs

If the fixed timestep is *faster* than the frame rate, fixed time step systems sometimes need to run catch-up, and are evaluated multiple times in the same frame. However, this will cause `just_pressed` (or `just_released`) to be registered as true multiple times (as `Input` will not update between these system evaluations.

This can cause extremely confusing behavior. Note that, unlike missed inputs, events should not be affected by this failure mode, due to the internal cursor stored in `EventReader`.

## Proposed fix

We should have a default fixed time step system set (see the stageless RFC). Input updating (and input event clearing) should occur in there, rather than as part of the main schedule.

Gameplay systems should effectively always be run in the fixed time step: only rendering-related code should be processed each frame.

Ping @maniwani for thoughts.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the fixed time step schedule and how Input::just_pressed, Input::just_released, and input event clearing are updated between evaluations. Read the referenced stageless RFC for the proposed schedule structure; done means fixed-step systems neither miss inputs nor register the same input repeatedly during catch-up runs.

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
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.