From 17435c711846b43119b3f00e382d4c3daf38c818 Mon Sep 17 00:00:00 2001 From: ickshonpe Date: Tue, 1 Apr 2025 20:49:39 +0100 Subject: [PATCH] Remove the `visited` local system param from `update_ui_context_system`. (#18664) # Objective The `visited: Local>` system param is meant to track which entities `update_contexts_recursively` has visited and updated but when the reparent_nodes_query isn't ordered descending from parent to child nodes can get marked as visited even though their camera target is unset and if the camera target is unset then the node won't be rendered. Fixes #18616 ## Solution Remove the `visited` system param from `update_ui_context_system` and the associated visited check from `update_contexts_recursively`. It was redundant anyway since the set_if_neq check is sufficient to track already updated nodes. ## Testing The example from #18616 can be used for testing. --- crates/bevy_ui/src/update.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index bb8752797b..88511453ce 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -9,10 +9,10 @@ use crate::{ use super::ComputedNode; use bevy_ecs::{ change_detection::DetectChangesMut, - entity::{Entity, EntityHashSet}, + entity::Entity, hierarchy::ChildOf, query::{Changed, With}, - system::{Commands, Local, Query, Res}, + system::{Commands, Query, Res}, }; use bevy_math::{Rect, UVec2}; use bevy_render::camera::Camera; @@ -139,9 +139,7 @@ pub fn update_ui_context_system( mut computed_target_query: Query<&mut ComputedNodeTarget>, ui_children: UiChildren, reparented_nodes: Query<(Entity, &ChildOf), (Changed, With)>, - mut visited: Local, ) { - visited.clear(); let default_camera_entity = default_ui_camera.get(); for root_entity in ui_root_nodes.iter() { @@ -172,7 +170,6 @@ pub fn update_ui_context_system( }, &ui_children, &mut computed_target_query, - &mut visited, ); } @@ -186,7 +183,6 @@ pub fn update_ui_context_system( *computed_target, &ui_children, &mut computed_target_query, - &mut visited, ); } } @@ -196,24 +192,14 @@ fn update_contexts_recursively( inherited_computed_target: ComputedNodeTarget, ui_children: &UiChildren, query: &mut Query<&mut ComputedNodeTarget>, - visited: &mut EntityHashSet, ) { - if !visited.insert(entity) { - return; - } if query .get_mut(entity) .map(|mut computed_target| computed_target.set_if_neq(inherited_computed_target)) .unwrap_or(false) { for child in ui_children.iter_ui_children(entity) { - update_contexts_recursively( - child, - inherited_computed_target, - ui_children, - query, - visited, - ); + update_contexts_recursively(child, inherited_computed_target, ui_children, query); } } }