Skip to content

Commit 18833fa

Browse files
authored
Fix reflected serialization/deserialization on Name component (#11447)
# Objective - This PR makes it so that `ReflectSerialize` and `ReflectDeserialize` traits are properly derived on `Name`. This avoids having the internal hash “leak” into the serialization when using reflection. ## Solution - Added a conditional derive for `ReflectDeserialize` and `ReflectSerialize` via `#[cfg_attr()]` --- ## Changelog - `Name` now implements `ReflectDeserialize` and `ReflectSerialize` whenever the `serialize` feature is enabled.
1 parent ffb6faa commit 18833fa

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

crates/bevy_core/src/name.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use std::{
1010
ops::Deref,
1111
};
1212

13+
#[cfg(feature = "serialize")]
14+
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
15+
1316
/// Component used to identify an entity. Stores a hash for faster comparisons.
1417
///
1518
/// The hash is eagerly re-computed upon each update to the name.
@@ -19,8 +22,9 @@ use std::{
1922
/// used instead as the default unique identifier.
2023
#[derive(Reflect, Component, Clone)]
2124
#[reflect(Component, Default, Debug)]
25+
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]
2226
pub struct Name {
23-
hash: u64, // TODO: Shouldn't be serialized
27+
hash: u64, // Won't be serialized (see: `bevy_core::serde` module)
2428
name: Cow<'static, str>,
2529
}
2630

0 commit comments

Comments
 (0)