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. DefaultTimefor most user code. Affected byTime<Virtual>::pause,set_relative_speed, and is whatTime::delta_secs()returns.Time<Fixed>— the fixed-timestep clock. Used by theFixedUpdateschedule.
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.rsKey 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:
- Sample real time and update
Time<Real>. - Compute virtual time delta from real time delta times the relative speed (and zero if paused), update
Time<Virtual>. - Replace the un-typed
Timeresource 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(forInstant). - Depended on by:
bevy_app(forRunFixedMainLoop), every gameplay system that usesTime,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>::overstepand the accumulator math. - Pause semantics:
virt.rs.
See also
bevy_app— orchestratesRunFixedMainLoop.bevy_diagnostic— theFrameCountresource.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.