Skip to content

Commit ad48f39

Browse files
authored
Skip picking for UI nodes if there is no pointer (#22074)
# Objective `ui_picking` always iterates through all the uinodes even if no hits are possible because there's no pointer above the current camera. ## Solution Early continue if no pointers are found on the current camera.
1 parent 1a9fee0 commit ad48f39

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

crates/bevy_ui/src/picking_backend.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ pub fn ui_picking(
174174
continue;
175175
};
176176

177-
let pointers_on_this_cam = pointer_pos_by_camera.get(&camera_entity);
177+
let Some(pointers_on_this_cam) = pointer_pos_by_camera.get(&camera_entity) else {
178+
continue;
179+
};
178180

179181
// Reverse the iterator to traverse the tree from closest nodes to furthest
180182
for node_entity in uinodes.iter().rev().cloned() {
@@ -203,8 +205,7 @@ pub fn ui_picking(
203205
// Find the normalized cursor position relative to the node.
204206
// (±0., 0.) is the center with the corners at points (±0.5, ±0.5).
205207
// Coordinates are relative to the entire node, not just the visible region.
206-
for (pointer_id, cursor_position) in pointers_on_this_cam.iter().flat_map(|h| h.iter())
207-
{
208+
for (pointer_id, cursor_position) in pointers_on_this_cam.iter() {
208209
if node.node.contains_point(*node.transform, *cursor_position)
209210
&& clip_check_recursive(
210211
*cursor_position,

0 commit comments

Comments
 (0)