diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index c7d79dcc088e8..c70d33286ccf8 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -325,6 +325,9 @@ pub struct ExtractedSprite { pub flip_x: bool, pub flip_y: bool, pub anchor: Vec2, + /// For cases where additional ExtractedSprites are created during extraction, this stores the + /// entity that caused that creation for use in determining visibility. + pub original_entity: Option, } #[derive(Resource, Default)] @@ -390,6 +393,7 @@ pub fn extract_sprites( flip_y: sprite.flip_y, image_handle_id: handle.id(), anchor: sprite.anchor.as_vec(), + original_entity: None, }, ); } @@ -425,6 +429,7 @@ pub fn extract_sprites( flip_y: atlas_sprite.flip_y, image_handle_id: texture_atlas.texture.id(), anchor: atlas_sprite.anchor.as_vec(), + original_entity: None, }, ); } @@ -550,7 +555,9 @@ pub fn queue_sprites( .reserve(extracted_sprites.sprites.len()); for (entity, extracted_sprite) in extracted_sprites.sprites.iter() { - if !view_entities.contains(entity.index() as usize) { + let index = extracted_sprite.original_entity.unwrap_or(*entity).index(); + + if !view_entities.contains(index as usize) { continue; } diff --git a/crates/bevy_text/src/text2d.rs b/crates/bevy_text/src/text2d.rs index dc066b26ae6a5..ffb285deba577 100644 --- a/crates/bevy_text/src/text2d.rs +++ b/crates/bevy_text/src/text2d.rs @@ -85,6 +85,7 @@ pub fn extract_text2d_sprite( windows: Extract>>, text2d_query: Extract< Query<( + Entity, &ViewVisibility, &Text, &TextLayoutInfo, @@ -100,7 +101,9 @@ pub fn extract_text2d_sprite( .unwrap_or(1.0); let scaling = GlobalTransform::from_scale(Vec2::splat(scale_factor.recip()).extend(1.)); - for (view_visibility, text, text_layout_info, anchor, global_transform) in text2d_query.iter() { + for (original_entity, view_visibility, text, text_layout_info, anchor, global_transform) in + text2d_query.iter() + { if !view_visibility.get() { continue; } @@ -125,8 +128,9 @@ pub fn extract_text2d_sprite( } let atlas = texture_atlases.get(&atlas_info.texture_atlas).unwrap(); + let entity = commands.spawn_empty().id(); extracted_sprites.sprites.insert( - commands.spawn_empty().id(), + entity, ExtractedSprite { transform: transform * GlobalTransform::from_translation(position.extend(0.)), color, @@ -136,6 +140,7 @@ pub fn extract_text2d_sprite( flip_x: false, flip_y: false, anchor: Anchor::Center.as_vec(), + original_entity: Some(original_entity), }, ); }