Remove the visited local system param from update_ui_context_system. (#18664)

# Objective

The `visited: Local<HashSet<Entity>>` 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.
This commit is contained in:
ickshonpe 2025-04-01 20:49:39 +01:00 committed by François Mockers
parent 9d4d110704
commit 8be04958c1

View File

@ -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<ChildOf>, With<ComputedNodeTarget>)>,
mut visited: Local<EntityHashSet>,
) {
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);
}
}
}