Skip to content

Commit 19682aa

Browse files
fredericvauchellesFrédéric Vauchelles
andauthored
Added derive Reflect to UntypedHandle and UntypedAssetId (#18827)
# Objective - We have the ability to serialize/deserialize `Handle<T>` 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<T>` 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 <frederic.vauchelles@outlook.com>
1 parent 2556405 commit 19682aa

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

crates/bevy_asset/src/handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ impl<A: Asset> From<&mut Handle<A>> for UntypedAssetId {
292292
/// to be stored together and compared.
293293
///
294294
/// See [`Handle`] for more information.
295-
#[derive(Clone)]
295+
#[derive(Clone, Reflect)]
296296
pub enum UntypedHandle {
297297
/// A strong handle, which will keep the referenced [`Asset`] alive until all strong handles are dropped.
298298
Strong(Arc<StrongHandle>),

crates/bevy_asset/src/id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<A: Asset> From<AssetIndex> for AssetId<A> {
164164
/// An "untyped" / "generic-less" [`Asset`] identifier that behaves much like [`AssetId`], but stores the [`Asset`] type
165165
/// information at runtime instead of compile-time. This increases the size of the type, but it enables storing asset ids
166166
/// across asset types together and enables comparisons between them.
167-
#[derive(Debug, Copy, Clone)]
167+
#[derive(Debug, Copy, Clone, Reflect)]
168168
pub enum UntypedAssetId {
169169
/// A small / efficient runtime identifier that can be used to efficiently look up an asset stored in [`Assets`]. This is
170170
/// the "default" identifier used for assets. The alternative(s) (ex: [`UntypedAssetId::Uuid`]) will only be used if assets are

0 commit comments

Comments
 (0)