Stepping FixedUpdate systems for unit testing?
#23585
Replies: 2 comments
-
|
I think you want to change the |
Beta Was this translation helpful? Give feedback.
-
|
I wasn't able to make it work, but I've found that bevy seems to enforce a maximum timestep of 250ms? While looking up some usage for I've changed the timestep like this: diff --git a/crates/bevy_time/src/lib.rs b/crates/bevy_time/src/lib.rs
index ebc63af94..dc87bc0fc 100644
--- a/crates/bevy_time/src/lib.rs
+++ b/crates/bevy_time/src/lib.rs
@@ -249,14 +249,18 @@ mod tests {
// Set the time step to just over half the fixed update timestep
// This way, it will have not accumulated enough time to run the fixed update after one update
// But will definitely have enough time after two updates
- let fixed_update_timestep = Time::<Fixed>::default().timestep();
+ let fixed_update_timestep = Duration::from_secs_f32(0.4);
+ // let fixed_update_timestep = Time::<Fixed>::default().timestep();
let time_step = fixed_update_timestep / 2 + Duration::from_millis(1);
+ println!("time step: {time_step:?}");
+
let mut app = App::new();
app.add_plugins(TimePlugin)
.add_systems(FixedUpdate, count_fixed_updates)
.add_systems(Update, report_time)
.init_resource::<FixedUpdateCounter>()
+ .insert_resource(Time::<Fixed>::from_duration(fixed_update_timestep))
.insert_resource(TimeUpdateStrategy::ManualDuration(time_step));
// Frame 0With a time step < 250ms this test logs what you would expect, e.g.: But trying to set a larger value, the step will be capped to 250 ms: For my own tests I can just set a smaller timestep no problem (I was just going for 1 second for cleaner numbers), but I wonder if this is intentional? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have some systems that rely on
FixedUpdate, and require the precise timings ofTime<Fixed>(so I can't add them under a regularUpdateschedule). Is there a way to step these systems in a unit test?The examples I've seen all use
Update, and callingapp.update()doesn't seem to runFixedUpdatesystems at all. Is there some equivalent that I'm missing here?Minimal example of what I've tried so far:
The test fails on the second assert like so:
My bevy version is 0.18.1
Beta Was this translation helpful? Give feedback.
All reactions