diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index 8924bf87de850..77cb6bddfa7e9 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -268,6 +268,13 @@ impl From<&mut Handle> for UntypedAssetId { } } +impl From for Handle { + #[inline] + fn from(uuid: Uuid) -> Self { + Handle::Uuid(uuid, PhantomData) + } +} + /// An untyped variant of [`Handle`], which internally stores the [`Asset`] type information at runtime /// as a [`TypeId`] instead of encoding it in the compile-time type. This allows handles across [`Asset`] types /// to be stored together and compared. @@ -626,6 +633,15 @@ mod tests { assert_eq!(UntypedHandle::from(typed.clone()), untyped); } + #[test] + fn from_uuid() { + let uuid = UUID_1; + let handle: Handle = uuid.into(); + + assert!(handle.is_uuid()); + assert_eq!(handle.id(), AssetId::Uuid { uuid }); + } + /// `PartialReflect::reflect_clone`/`PartialReflect::to_dynamic` should increase the strong count of a strong handle #[test] fn strong_handle_reflect_clone() {