diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index 19065ae6e84fa..e189b1924354c 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 10a1bcd8f6d4b..6cefa7c23b8b3 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -201,6 +201,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},