Open-Source Wikis

/

Bevy

/

Packages

/

bevy_time

bevyengine/bevy

bevy_time

Time and the fixed-timestep loop. Provides Time<Real>, Time<Virtual>, Time<Fixed>, Timer, and Stopwatch.

Purpose

Bevy distinguishes between three flavors of time:

  • Time<Real> — wall-clock time. Always advances at the rate the wall clock does.
  • Time<Virtual> — game time. Default Time for most user code. Affected by Time<Virtual>::pause, set_relative_speed, and is what Time::delta_secs() returns.
  • Time<Fixed> — the fixed-timestep clock. Used by the FixedUpdate schedule.

Plus Timer (count-down with optional repeat) and Stopwatch (count-up).

Directory layout

crates/bevy_time/src/
├── lib.rs
├── time.rs        # Time<C> + Real / Virtual / Fixed types
├── fixed.rs       # Fixed-timestep accumulator
├── virt.rs        # Virtual time (pause / scale)
├── real.rs        # Real time
├── timer.rs       # Timer
├── stopwatch.rs   # Stopwatch
└── prelude.rs

Key abstractions

Type File Description
Time<C> crates/bevy_time/src/time.rs Generic time resource parameterized by clock type.
Real / Virtual / Fixed crates/bevy_time/src/{real,virt,fixed}.rs The three time contexts.
Timer crates/bevy_time/src/timer.rs Count-down with tick / finished API.
Stopwatch crates/bevy_time/src/stopwatch.rs Count-up.
TimePlugin crates/bevy_time/src/lib.rs Inserts the resources and runs the tick systems.

How it works

TimePlugin sets up systems in First that:

  1. Sample real time and update Time<Real>.
  2. Compute virtual time delta from real time delta times the relative speed (and zero if paused), update Time<Virtual>.
  3. Replace the un-typed Time resource with the active virtual clock so user systems see virtual time by default.

The fixed-timestep accumulator lives in bevy_app::main_schedule.rs (the RunFixedMainLoop schedule) and ticks Time<Fixed> once per FixedUpdate invocation. Users can read Time<Fixed> inside FixedUpdate to get the fixed delta (default 1/64 s).

Integration points

  • Depends on: bevy_app, bevy_ecs, bevy_reflect, bevy_platform (for Instant).
  • Depended on by: bevy_app (for RunFixedMainLoop), every gameplay system that uses Time, bevy_diagnostic, bevy_animation, bevy_render (for global uniform), …

Entry points for modification

  • Custom clock type: define a new type, implement the Time<C> plumbing, add a tick system.
  • Fixed-timestep tuning: Time<Fixed>::overstep and the accumulator math.
  • Pause semantics: virt.rs.

See also

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

bevy_time – Bevy wiki | Factory