From ca5712a7bf19f20a3cde6c6dd503f720d1be9db4 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 22 May 2025 20:30:14 +0200 Subject: [PATCH] feat: derive Serialize on Childof (#19336) # Objective allow serialization / deserialization on the `ChildOf` entity, for example in network usage. my usage was for the bevy_replicon crate, to replicate `ChildOf`. ## Solution same implementation of serde as other types in the bevy repo --------- Co-authored-by: Hennadii Chernyshchyk --- crates/bevy_ecs/src/hierarchy.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/hierarchy.rs b/crates/bevy_ecs/src/hierarchy.rs index 53be7fc80b..6fd66b0bb6 100644 --- a/crates/bevy_ecs/src/hierarchy.rs +++ b/crates/bevy_ecs/src/hierarchy.rs @@ -19,6 +19,8 @@ use crate::{ use alloc::{format, string::String, vec::Vec}; #[cfg(feature = "bevy_reflect")] use bevy_reflect::std_traits::ReflectDefault; +#[cfg(all(feature = "serialize", feature = "bevy_reflect"))] +use bevy_reflect::{ReflectDeserialize, ReflectSerialize}; use core::ops::Deref; use core::slice; use disqualified::ShortName; @@ -96,9 +98,14 @@ use log::warn; feature = "bevy_reflect", reflect(Component, PartialEq, Debug, FromWorld, Clone) )] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + all(feature = "serialize", feature = "bevy_reflect"), + reflect(Serialize, Deserialize) +)] #[relationship(relationship_target = Children)] #[doc(alias = "IsChild", alias = "Parent")] -pub struct ChildOf(pub Entity); +pub struct ChildOf(#[entities] pub Entity); impl ChildOf { /// The parent entity of this child entity.