FixedTimestep can have unexpected delta_seconds
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
0.5
## Operating system & version
Ubuntu 20.04
## What you did
Running the following code on a debug build (`cargo run`), if I move the window around, I get dt values that are significantly less than the desired fixed timestep:
```
use bevy::core::FixedTimestep;
use bevy::prelude::*;
use bevy::utils::tracing;
const FIXED_STEP: f32 = 0.02;
const FIXED_STEP_MIN: f32 = FIXED_STEP / 2.0;
const FIXED_STEP_MAX: f32 = FIXED_STEP * 2.0;
#[tracing::instrument]
fn instrumented_fixed_update(dt: f32) {
if dt < FIXED_STEP_MIN || dt > FIXED_STEP_MAX {
info!("unexpected physics step, expected {}", FIXED_STEP);
}
}
fn fixed_update(time: Res
#[bevy_main]
fn main() {
App::build()
.add_plugins(DefaultPlugins)
.add_system_set(
SystemSet::new()
.with_run_criteria(FixedTimestep::step(FIXED_STEP as f64))
.with_system(fixed_update.system()),
)
.run();
}
```
```
...
Apr 28 21:01:29.019 INFO instrumented_fixed_update{dt=0.006083767}: physics: unexpected physics step, expected 0.02
Apr 28 21:01:29.019 INFO instrumented_fixed_update{dt=0.006083767}: physics: unexpected physics step, expected 0.02
Apr 28 21:01:29.019 INFO instrumented_fixed_update{dt=0.006083767}: physics: unexpected physics step, expected 0.02
Apr 28 21:01:29.020 INFO instrumented_fixed_update{dt=0.006083767}: physics: unexpected physics step, expected 0.02
...
```
Additionally, the fixed_update() method is called repeatedly on startup with larger dts (this does clear out after a second or so of runtime):
```
...
Apr 28 21:02:14.581 INFO instrumented_fixed_update{dt=0.07785423}: physics: unexpected physics step, expected 0.02
Apr 28 21:02:14.581 INFO instrumented_fixed_update{dt=0.07785423}: physics: unexpected physics step, expected 0.02
Apr 28 21:02:14.581 INFO instrumented_fixed_update{dt=0.07785423}: physics: unexpected physics step, expected 0.02
Apr 28 21:02:14.581 INFO instrumented_fixed_update{dt=0.07785423}: physics: unexpected physics step, expected 0.02
...
```
I haven't seen anything in the documentation so far that would lead me to expect either of these scenarios. I have a more complex example of this that I wish made for a simpler example in which my simulation is ok in a debug run but in a release run does effectively nothing because I constantly get dts that are significantly less than the expected step (similar to the dt values I get when I just move the window around in the simple example).
Is there something that I'm missing with the FixedTimestep that could get me back on track to having dt's closer to my required step size? Or is what I'm experiencing here actually the expected result (I imagine not consider what's happening in my more complex simulation using a release build, but I'm unsure).
Contributor guide
Assessment
This issue has not been assessed yet.