diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index f38c60c203f9a..3c4e0708ab948 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -45,7 +45,7 @@ wav = ["bevy_audio/wav"] # Enable watching file system for asset hot reload filesystem_watcher = ["bevy_asset/filesystem_watcher"] -serialize = ["bevy_input/serialize", "bevy_window/serialize"] +serialize = ["bevy_input/serialize", "bevy_time/serialize", "bevy_window/serialize"] # Display server protocol support (X11 is enabled by default) wayland = ["bevy_winit/wayland"] diff --git a/crates/bevy_time/Cargo.toml b/crates/bevy_time/Cargo.toml index 7ce9db0ff042b..80f3ea8afe507 100644 --- a/crates/bevy_time/Cargo.toml +++ b/crates/bevy_time/Cargo.toml @@ -8,6 +8,9 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy"] +[features] +default = [] +serialize = ["serde"] [dependencies] # bevy @@ -18,3 +21,4 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" } # other crossbeam-channel = "0.5.0" +serde = { version = "1", features = ["derive"], optional = true } diff --git a/crates/bevy_time/src/stopwatch.rs b/crates/bevy_time/src/stopwatch.rs index 299ec1aa936a5..2dd925e4efb55 100644 --- a/crates/bevy_time/src/stopwatch.rs +++ b/crates/bevy_time/src/stopwatch.rs @@ -24,6 +24,7 @@ use bevy_utils::Duration; /// assert_eq!(stopwatch.elapsed_secs(), 0.0); /// ``` #[derive(Clone, Debug, Default, Reflect)] +#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))] #[reflect(Default)] pub struct Stopwatch { elapsed: Duration, diff --git a/crates/bevy_time/src/timer.rs b/crates/bevy_time/src/timer.rs index 6fbdfdc41840d..767c79d91b9a7 100644 --- a/crates/bevy_time/src/timer.rs +++ b/crates/bevy_time/src/timer.rs @@ -10,6 +10,7 @@ use bevy_utils::Duration; /// /// Paused timers will not have elapsed time increased. #[derive(Clone, Debug, Default, Reflect)] +#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))] #[reflect(Default)] pub struct Timer { stopwatch: Stopwatch, @@ -401,6 +402,7 @@ impl Timer { /// Specifies [`Timer`] behavior. #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Default, Reflect)] +#[cfg_attr(feature = "serialize", derive(serde::Deserialize, serde::Serialize))] #[reflect(Default)] pub enum TimerMode { /// Run once and stop.