From 227031fb826104ba405c8ef5be7031b4691caf3b Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:19:10 +0100 Subject: [PATCH] Avoid panicking with non-UI nodes --- crates/bevy_ui/src/layout/mod.rs | 4 +++- crates/bevy_ui/src/update.rs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ui/src/layout/mod.rs b/crates/bevy_ui/src/layout/mod.rs index 31f123ff6d3f5..df3ac93372bb6 100644 --- a/crates/bevy_ui/src/layout/mod.rs +++ b/crates/bevy_ui/src/layout/mod.rs @@ -411,7 +411,9 @@ pub fn ui_layout_system( mut absolute_location: Vec2, ) { if let Ok((mut node, mut transform)) = node_transform_query.get_mut(entity) { - let layout = ui_surface.get_layout(entity).unwrap(); + let Ok(layout) = ui_surface.get_layout(entity) else { + return; + }; let layout_size = inverse_target_scale_factor * Vec2::new(layout.size.width, layout.size.height); let layout_location = diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index 44faa3d42bae1..d3750996d9398 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -155,7 +155,9 @@ fn update_children_target_camera( for &child in children { // Skip if the child has already been updated or update is not needed - if updated_entities.contains(&child) || camera_to_set == node_query.get(child).unwrap() { + if updated_entities.contains(&child) + || camera_to_set == node_query.get(child).ok().flatten() + { continue; }