Time is faster for unfocused windows
Bevy version
0.13.2
[Optional] Relevant system information
AdapterInfo { name: "NVIDIA GeForce RTX 2060", vendor: 4318, device: 7944, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "551.86", backend: Vulkan }
What you did
- Run an example with an inspector plugin.
- Click on the window.
- Note
Time<Virtual>'selapsedanddelta. - Click out of the window.
-
elapsedaccumulates faster anddeltais erratic.
What went wrong
I expected the virtual timer to tick at the same speed regardless of window focus state.
Additional information
I tried to replicate this locally, here's my findings!
@cuppachino , where is the LogicStep type from?
And I'm curious, is your bug report that the timer in the LogicStep type advanced more quickly than you intended, or that when a window is unfocused the update rate has different characteristics?
Experiment Setup
The example program I used
[package]
name = "time_test"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy="*"
bevy-inspector-egui = "*"
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
use bevy::{input::common_conditions::input_toggle_active, prelude::*};
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
//present_mode: bevy::window::PresentMode::Immediate,
..default()
}),
..default()
}))
.add_plugins(
bevy_inspector_egui::quick::WorldInspectorPlugin::default()
.run_if(input_toggle_active(true, KeyCode::Escape)),
)
.run();
}
My findings
Virtual Time (TLDR: Appears WAI on my machine)
I did find Virtual and Real time elapsed at slightly different rates, but it was minimally different, less than a second over a hundred seconds.
Virtual time seems consistent based on the elapsed time of the previous update tick, and adapted based on the update loop time. For me it seems it advances roughly close to real time, besides jump discontinuities when I drag the window where real time advances, but virtual time is paused during the drag.
Fixed time (TLDR: Appears WAI on my machine)
I adjusted my Fixed timestep to step to 0.5 seconds, and it advanced at a consistent rate (although jumping every 0.5 seconds) focused or unfocused, relative to Virtual time. It appears at least on my machine to be fairly consistent.
LogicStep time (The problem banana that I can not find)
I do not see this type in Bevy's libraries, but this appears to be the type that is having the rate issue.
Was this a name of a previously removed type?
@Earthmark LogicStep is essentially a duplicate of Fixed. My mistake was running the modified run_fixed_main_schedule in FixedMain.
Very sorry for wasting your time, but thank you for the detailed analysis! I thought it was a problem with the Virtual time affecting other timers, but that's probably because I was updating the virtual timer outside of the RunFixedMainLoop.
app.init_schedule(LogicUpdate)
.add_systems(
- FixedMain,
+ bevy::app::RunFixedMainLoop,
run_fixed_main_schedule
);
The issue can probably be closed.