From 19682aa4c3a6147f2fd34e1d2349a9d246dead73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Vauchelles?= Date: Mon, 28 Apr 2025 21:46:36 +0000 Subject: [PATCH] Added derive Reflect to UntypedHandle and UntypedAssetId (#18827) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Objective - We have the ability to serialize/deserialize `Handle` with [`TypedReflectSerializer`](https://docs.rs/bevy/latest/bevy/reflect/serde/struct.TypedReflectSerializer.html) and [`TypedReflectDeserializer`](https://docs.rs/bevy/latest/bevy/reflect/serde/struct.TypedReflectDeserializer.html), but it is not possible for `UntypedHandle`. - `Handle` already has the `Reflect` derive, so it sounds coherent to also have this derive also on the untyped API ## Solution - Add the `Reflect` derive macro to both `UntypedHandle` and ` UntypedAssetId`. ## Testing - I used a custom processor to handle the serialization based on the example of [`TypedReflectSerializer`](https://docs.rs/bevy/latest/bevy/reflect/serde/struct.TypedReflectSerializer.html) (see [source code](https://docs.rs/bevy_reflect/0.15.3/src/bevy_reflect/serde/ser/serializer.rs.html#149)) Co-authored-by: Frédéric Vauchelles --- crates/bevy_asset/src/handle.rs | 2 +- crates/bevy_asset/src/id.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index e6ad1d074a..a78c43ffdd 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -292,7 +292,7 @@ impl From<&mut Handle> for UntypedAssetId { /// to be stored together and compared. /// /// See [`Handle`] for more information. -#[derive(Clone)] +#[derive(Clone, Reflect)] pub enum UntypedHandle { /// A strong handle, which will keep the referenced [`Asset`] alive until all strong handles are dropped. Strong(Arc), diff --git a/crates/bevy_asset/src/id.rs b/crates/bevy_asset/src/id.rs index f9aa0d1b96..78686e31c2 100644 --- a/crates/bevy_asset/src/id.rs +++ b/crates/bevy_asset/src/id.rs @@ -164,7 +164,7 @@ impl From for AssetId { /// An "untyped" / "generic-less" [`Asset`] identifier that behaves much like [`AssetId`], but stores the [`Asset`] type /// information at runtime instead of compile-time. This increases the size of the type, but it enables storing asset ids /// across asset types together and enables comparisons between them. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Reflect)] pub enum UntypedAssetId { /// A small / efficient runtime identifier that can be used to efficiently look up an asset stored in [`Assets`]. This is /// the "default" identifier used for assets. The alternative(s) (ex: [`UntypedAssetId::Uuid`]) will only be used if assets are