diff --git a/crates/bevy_asset/src/assets.rs b/crates/bevy_asset/src/assets.rs index 154e20907954f..97b30dd53d904 100644 --- a/crates/bevy_asset/src/assets.rs +++ b/crates/bevy_asset/src/assets.rs @@ -33,21 +33,21 @@ impl Debug for AssetEvent { "AssetEvent<{}>::Created", std::any::type_name::() )) - .field("handle", &handle.id) + .field("handle", &handle.id()) .finish(), AssetEvent::Modified { handle } => f .debug_struct(&format!( "AssetEvent<{}>::Modified", std::any::type_name::() )) - .field("handle", &handle.id) + .field("handle", &handle.id()) .finish(), AssetEvent::Removed { handle } => f .debug_struct(&format!( "AssetEvent<{}>::Removed", std::any::type_name::() )) - .field("handle", &handle.id) + .field("handle", &handle.id()) .finish(), } } diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index abd6e13a98b79..4b1bab01a8ab3 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -105,8 +105,7 @@ pub struct Handle where T: Asset, { - /// The ID of the asset as contained within its respective [`Assets`] collection - pub id: HandleId, + id: HandleId, #[reflect(ignore)] handle_type: HandleType, #[reflect(ignore)] @@ -151,6 +150,12 @@ impl Handle { } } + /// The ID of the asset as contained within its respective [`Assets`] collection. + #[inline] + pub fn id(&self) -> HandleId { + self.id + } + /// Recasts this handle as a weak handle of an Asset `U`. pub fn as_weak(&self) -> Handle { Handle { diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 35f09d8a2f2a8..49e5e0d7f38ef 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -261,7 +261,7 @@ pub fn extract_sprites( custom_size: sprite.custom_size, flip_x: sprite.flip_x, flip_y: sprite.flip_y, - image_handle_id: handle.id, + image_handle_id: handle.id(), anchor: sprite.anchor.as_vec(), }); } @@ -281,7 +281,7 @@ pub fn extract_sprites( custom_size: atlas_sprite.custom_size, flip_x: atlas_sprite.flip_x, flip_y: atlas_sprite.flip_y, - image_handle_id: texture_atlas.texture.id, + image_handle_id: texture_atlas.texture.id(), anchor: atlas_sprite.anchor.as_vec(), }); } diff --git a/crates/bevy_text/src/pipeline.rs b/crates/bevy_text/src/pipeline.rs index 3d05b414f260a..c3b85317e1c59 100644 --- a/crates/bevy_text/src/pipeline.rs +++ b/crates/bevy_text/src/pipeline.rs @@ -34,7 +34,7 @@ impl TextPipeline { let brush = &mut self.brush; *self .map_font_id - .entry(handle.id) + .entry(handle.id()) .or_insert_with(|| brush.add_font(handle.clone(), font.font.clone())) } diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index 3711513e81a95..8097db3e5cddc 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -134,7 +134,7 @@ pub fn extract_text2d_sprite( color, rect, custom_size: None, - image_handle_id: handle.id, + image_handle_id: handle.id(), flip_x: false, flip_y: false, anchor: Anchor::Center.as_vec(),