Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/bevy_asset/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ impl<A: Asset> From<&mut Handle<A>> for UntypedAssetId {
}
}

impl<A: Asset> From<Uuid> for Handle<A> {
#[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.
Expand Down Expand Up @@ -626,6 +633,21 @@ mod tests {
assert_eq!(UntypedHandle::from(typed.clone()), untyped);
}

/// `Handle` should be created from a `Uuid` via `From` trait
#[test]
fn from_uuid() {
let uuid = UUID_1;
let handle: Handle<TestAsset> = uuid.into();

assert!(handle.is_uuid());
assert_eq!(handle.id(), AssetId::Uuid { uuid });

// Should also work with explicit From::from
let handle2 = Handle::<TestAsset>::from(UUID_2);
assert!(handle2.is_uuid());
assert_eq!(handle2.id(), AssetId::Uuid { uuid: UUID_2 });
}

/// `PartialReflect::reflect_clone`/`PartialReflect::to_dynamic` should increase the strong count of a strong handle
#[test]
fn strong_handle_reflect_clone() {
Expand Down