Camera clear_color does not work with multiple cameras
Bevy version
0.15.1
[Optional] Relevant system information
SystemInfo { os: "MacOS 15.2 ", kernel: "24.2.0", cpu: "Apple M2 Pro", core_count: "12", memory: "16.0 GiB" }
AdapterInfo { name: "Apple M2 Pro", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
What you did
I have 2 Cameras, with different Viewports and a different clear_color per camera. Instead of each viewport rendering with it's own clear_color, both viewports are rendered with the clear_color of the camera with the lowest order.
use bevy::{
app::{App, Startup},
color::palettes::basic::{GREEN, RED},
prelude::*,
render::camera::Viewport,
DefaultPlugins,
};
fn main() {
App::new()
.add_plugins((DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: (400., 400.).into(),
..default()
}),
..default()
}),))
.add_systems(Startup, setup)
.run();
}
pub fn setup(mut commands: Commands, window: Single<&Window>) {
let size = window.physical_size();
commands.spawn((
Camera2d,
Camera {
order: 0,
clear_color: ClearColorConfig::Custom(RED.into()),
viewport: Some(Viewport {
physical_size: size / 2,
..default()
}),
..default()
},
));
commands.spawn((
Camera2d,
Camera {
order: 1,
clear_color: ClearColorConfig::Custom(GREEN.into()),
viewport: Some(Viewport {
physical_size: size / 2,
physical_position: size / 2,
..default()
}),
..default()
},
));
}
What went wrong
In the above example, both viewports are rendered with red clear_color. If I then swap their Camera.order, then both are rendered with green clear_color.
They should each render with their specified clear_color.
Additional information
Hi! I'm currently working on a university project where I contribute to an open-source project of my choice. I found this issue interesting and would like to work on it. Would it be okay if I take it?
That would be lovely; please go ahead!
Ha, I hit this and came up with almost the exact same repro (bevy 0.17.3):