diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index 690d5061bd..931fb3fb69 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -501,6 +501,24 @@ impl TryFrom for Handle { } } +/// Creates a weak [`Handle`] from a string literal containing a UUID. +/// +/// # Examples +/// +/// ``` +/// # use bevy_asset::{Handle, weak_handle}; +/// # type Shader = (); +/// const SHADER: Handle = weak_handle!("1347c9b7-c46a-48e7-b7b8-023a354b7cac"); +/// ``` +#[macro_export] +macro_rules! weak_handle { + ($uuid:expr) => {{ + $crate::Handle::Weak($crate::AssetId::Uuid { + uuid: $crate::uuid::uuid!($uuid), + }) + }}; +} + /// Errors preventing the conversion of to/from an [`UntypedHandle`] and a [`Handle`]. #[derive(Error, Debug, PartialEq, Clone)] #[non_exhaustive] diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index a3211fe2b3..8fb2a3da74 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -202,6 +202,7 @@ pub use server::*; /// Rusty Object Notation, a crate used to serialize and deserialize bevy assets. pub use ron; +pub use uuid; use crate::{ io::{embedded::EmbeddedAssetRegistry, AssetSourceBuilder, AssetSourceBuilders, AssetSourceId},