Skip to content

Conversation

@janhohenheim
Copy link
Member

@janhohenheim janhohenheim commented Oct 31, 2025

Objective

  • For running tests involving fixed timesteps, I want to advance the time so that every call to app.update() triggers a fixed update
  • Right now, the most precise way to do that to my knowledge is
    app.insert_resource(TimeUpdateStrategy::ManualDuration(Time::<Fixed>::default().timestep()))
  • But this is a bit clumsy, and also doesn't work when the fixed timestep isn't at the default. Some more boilerplate would be needed in the test setup to deal with that:
    app.insert_resource(TimeUpdateStrategy::ManualDuration(app.world().resource::<Time<Fixed>>().timestep()))
  • Good luck adapting this for the case when the fixed timestep ever changes at runtime lol

Solution

  • Create an alternative strategy called TimeUpdateStrategy::FixedTimesteps that advances time by the fixed timestep automatically:
    // Now `app.update()` will run the fixed loop exactly once!
    app.insert_resource(TimeUpdateStrategy::FixedTimesteps(1))

Testing

  • None, as this is trivial

@janhohenheim janhohenheim added D-Trivial Nice and easy! A great choice to get started with Bevy C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Time Involves time keeping and reporting labels Oct 31, 2025
@janhohenheim janhohenheim added this to the 0.18 milestone Oct 31, 2025
@andriyDev andriyDev added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 31, 2025
@janhohenheim janhohenheim changed the title Expose default timestep Make it easier to write tests involving fixed timesteps Oct 31, 2025
@janhohenheim janhohenheim added D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Oct 31, 2025
@janhohenheim janhohenheim added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Oct 31, 2025
Copy link

@Ownezx Ownezx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps making sure that the u32 is non zero would avoid silliness?

That being said it's clear enough that zero would likely not be used.

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved on behalf of @NiseVoid

@janhohenheim
Copy link
Member Author

image

@janhohenheim
Copy link
Member Author

janhohenheim commented Oct 31, 2025

@Ownezx well, 0 is a valid state here: using 0 will in fact ensure that the fixed timestep is never run. Might be useful for disabling fixed updates in a test? Though it would also not advance time at all, so idk how useful that would be in practice.

@mockersf mockersf added this pull request to the merge queue Nov 1, 2025
Merged via the queue into bevyengine:main with commit a223c1a Nov 1, 2025
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Time Involves time keeping and reporting C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants