Skip to content

Commit f4800d1

Browse files
ickshonpemrchantey
authored andcommitted
no-camera many_buttons argument, only emit UI camera warnings once (bevyengine#17557)
# Objective * Add a `no-camera` argument to the `many_buttons` stress test example. * Only emit the UI "no camera found" warnings once.
1 parent a09cd1e commit f4800d1

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

crates/bevy_ui/src/layout/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use bevy_math::{UVec2, Vec2};
1212
use bevy_render::camera::{Camera, NormalizedRenderTarget};
1313
use bevy_sprite::BorderRect;
1414
use bevy_transform::components::Transform;
15+
use bevy_utils::once;
1516
use bevy_window::{PrimaryWindow, Window, WindowScaleFactorChanged};
1617
use thiserror::Error;
1718
use tracing::warn;
@@ -164,10 +165,10 @@ pub fn ui_layout_system(
164165
match camera_with_default(target_camera) {
165166
Some(camera_entity) => {
166167
let Ok((_, camera)) = cameras.get(camera_entity) else {
167-
warn!(
168+
once!(warn!(
168169
"UiTargetCamera (of root UI node {entity}) is pointing to a camera {} which doesn't exist",
169170
camera_entity
170-
);
171+
));
171172
return;
172173
};
173174
let layout_info = camera_layout_info
@@ -177,13 +178,13 @@ pub fn ui_layout_system(
177178
}
178179
None => {
179180
if cameras.is_empty() {
180-
warn!("No camera found to render UI to. To fix this, add at least one camera to the scene.");
181+
once!(warn!("No camera found to render UI to. To fix this, add at least one camera to the scene."));
181182
} else {
182-
warn!(
183+
once!(warn!(
183184
"Multiple cameras found, causing UI target ambiguity. \
184185
To fix this, add an explicit `UiTargetCamera` component to the root UI node {}",
185186
entity
186-
);
187+
));
187188
}
188189
}
189190
}

examples/stress_tests/many_buttons.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ struct Args {
5050
/// set the root node to display none, removing all nodes from the layout.
5151
#[argh(switch)]
5252
display_none: bool,
53+
54+
/// spawn the layout without a camera
55+
#[argh(switch)]
56+
no_camera: bool,
5357
}
5458

5559
/// This example shows what happens when there is a lot of buttons on screen.
@@ -82,9 +86,11 @@ fn main() {
8286
})
8387
.add_systems(Update, (button_system, set_text_colors_changed));
8488

85-
app.add_systems(Startup, |mut commands: Commands| {
86-
commands.spawn(Camera2d);
87-
});
89+
if !args.no_camera {
90+
app.add_systems(Startup, |mut commands: Commands| {
91+
commands.spawn(Camera2d);
92+
});
93+
}
8894

8995
if args.grid {
9096
app.add_systems(Startup, setup_grid);

0 commit comments

Comments
 (0)