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.
This commit is contained in:
parent
ffb6faafc2
commit
18833fa67c
@ -10,6 +10,9 @@ use std::{
|
|||||||
ops::Deref,
|
ops::Deref,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "serialize")]
|
||||||
|
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
|
||||||
|
|
||||||
/// Component used to identify an entity. Stores a hash for faster comparisons.
|
/// Component used to identify an entity. Stores a hash for faster comparisons.
|
||||||
///
|
///
|
||||||
/// The hash is eagerly re-computed upon each update to the name.
|
/// The hash is eagerly re-computed upon each update to the name.
|
||||||
@ -19,8 +22,9 @@ use std::{
|
|||||||
/// used instead as the default unique identifier.
|
/// used instead as the default unique identifier.
|
||||||
#[derive(Reflect, Component, Clone)]
|
#[derive(Reflect, Component, Clone)]
|
||||||
#[reflect(Component, Default, Debug)]
|
#[reflect(Component, Default, Debug)]
|
||||||
|
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]
|
||||||
pub struct Name {
|
pub struct Name {
|
||||||
hash: u64, // TODO: Shouldn't be serialized
|
hash: u64, // Won't be serialized (see: `bevy_core::serde` module)
|
||||||
name: Cow<'static, str>,
|
name: Cow<'static, str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user