diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index abd6e13a98b79..9d1a4665e0d6d 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -152,9 +152,15 @@ impl Handle { } /// Recasts this handle as a weak handle of an Asset `U`. - pub fn as_weak(&self) -> Handle { + pub fn cast_weak(&self) -> Handle { + let id = if let HandleId::Id(_, id) = self.id { + HandleId::Id(U::TYPE_UUID, id) + } else { + self.id + }; + Handle { - id: self.id, + id, handle_type: HandleType::Weak, marker: PhantomData, } diff --git a/crates/bevy_text/src/glyph_brush.rs b/crates/bevy_text/src/glyph_brush.rs index ca7331901775d..34fb6aa357695 100644 --- a/crates/bevy_text/src/glyph_brush.rs +++ b/crates/bevy_text/src/glyph_brush.rs @@ -96,7 +96,7 @@ impl GlyphBrush { let section_data = sections_data[sg.section_index]; if let Some(outlined_glyph) = section_data.1.font.outline_glyph(glyph) { let bounds = outlined_glyph.px_bounds(); - let handle_font_atlas: Handle = section_data.0.as_weak(); + let handle_font_atlas: Handle = section_data.0.cast_weak(); let font_atlas_set = font_atlas_set_storage .get_or_insert_with(handle_font_atlas, FontAtlasSet::default); diff --git a/examples/ui/font_atlas_debug.rs b/examples/ui/font_atlas_debug.rs index 71e9808cdeb68..dc9c583ca6e8d 100644 --- a/examples/ui/font_atlas_debug.rs +++ b/examples/ui/font_atlas_debug.rs @@ -36,7 +36,7 @@ fn atlas_render_system( font_atlas_sets: Res>, texture_atlases: Res>, ) { - if let Some(set) = font_atlas_sets.get(&state.handle.as_weak::()) { + if let Some(set) = font_atlas_sets.get(&state.handle.cast_weak::()) { if let Some((_size, font_atlas)) = set.iter().next() { let x_offset = state.atlas_count as f32; if state.atlas_count == font_atlas.len() as u32 {