Skip to content

Commit a785e3c

Browse files
authored
Fix UI elements randomly not appearing after #13277. (#13462)
We invoked the `extract_default_ui_camera_view` system twice: once for 2D cameras and once for 3D cameras. This was fine before moving to resources for render phases, but, after the move to resources, the first thing such systems do is to clear out all the entities-to-be-rendered from the previous frame. So, if the scheduler happened to run `extract_default_ui_camera_view::<Camera2d>` first, then all the UI elements that it queued would be overwritten by the `extract_default_ui_camera_view::<Camera3d>` system, or vice versa. The ordering dependence is the reason why this problem was intermittent. This commit fixes the problem by merging the two systems into one systems, using an `Or` query filter. ## Migration Guide * The `bevy_ui::render::extract_default_ui_camera_view` system is no longer parameterized over the specific type of camera and is hard-wired to either `Camera2d` or `Camera3d` components.
1 parent 6c95d54 commit a785e3c

File tree

1 file changed

+4
-4
lines changed
  • crates/bevy_ui/src/render

1 file changed

+4
-4
lines changed

crates/bevy_ui/src/render/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ pub fn build_ui_render(app: &mut App) {
101101
.add_systems(
102102
ExtractSchedule,
103103
(
104-
extract_default_ui_camera_view::<Camera2d>,
105-
extract_default_ui_camera_view::<Camera3d>,
104+
extract_default_ui_camera_view,
106105
extract_uinode_background_colors.in_set(RenderUiSystem::ExtractBackgrounds),
107106
extract_uinode_images.in_set(RenderUiSystem::ExtractImages),
108107
extract_uinode_borders.in_set(RenderUiSystem::ExtractBorders),
@@ -657,11 +656,12 @@ const UI_CAMERA_TRANSFORM_OFFSET: f32 = -0.1;
657656
#[derive(Component)]
658657
pub struct DefaultCameraView(pub Entity);
659658

660-
pub fn extract_default_ui_camera_view<T: Component>(
659+
/// Extracts all UI elements associated with a camera into the render world.
660+
pub fn extract_default_ui_camera_view(
661661
mut commands: Commands,
662662
mut transparent_render_phases: ResMut<ViewSortedRenderPhases<TransparentUi>>,
663663
ui_scale: Extract<Res<UiScale>>,
664-
query: Extract<Query<(Entity, &Camera), With<T>>>,
664+
query: Extract<Query<(Entity, &Camera), Or<(With<Camera2d>, With<Camera3d>)>>>,
665665
mut live_entities: Local<EntityHashSet>,
666666
) {
667667
live_entities.clear();

0 commit comments

Comments
 (0)