diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 1b92d00d8911c..eb0f7007229aa 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -114,9 +114,16 @@ impl Plugin for TaskPoolPlugin { } } -/// Keeps a count of rendered frames since the start of the app +/// Maintains a count of frames rendered since the start of the application. /// -/// Wraps to 0 when it reaches the maximum u32 value +/// [`FrameCount`] is incremented during [`CoreStage::Last`], providing predictable +/// behaviour: it will be 0 during the first update, 1 during the next, and so forth. +/// +/// # Overflows +/// +/// [`FrameCount`] will wrap to 0 after exceeding [`u32::MAX`]. Within reasonable +/// assumptions, one may exploit wrapping arithmetic to determine the number of frames +/// that have elapsed between two observations – see [`u32::wrapping_sub()`]. #[derive(Default, Resource, Clone, Copy)] pub struct FrameCount(pub u32); @@ -127,7 +134,7 @@ pub struct FrameCountPlugin; impl Plugin for FrameCountPlugin { fn build(&self, app: &mut App) { app.init_resource::(); - app.add_system(update_frame_count); + app.add_system_to_stage(CoreStage::Last, update_frame_count); } }