bevyengine / bevyengine/bevy

Inactive Camera with higher priority hides the menu

Open
#17,546 1 comment 0 reactions 0 assignees View on GitHub
A-Rendering A-UI C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
4d 8m
Merged PRs (30d)
147

Description

I believe this is a bug. Apologies if it is just me misunderstanding how the UI/Cameras is supposed to work. Thanks for the nice bevy crate!

## Bevy version

```
name = "bevy"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2a21c9f3306676077a88700bb8f354be779cf9caba9c21e94da9e696751af4"
dependencies = [
"bevy_dylib",
"bevy_internal",
]
```

## \[Optional\] Relevant system information
* Rust version:
* ` cargo 1.83.0 (5ffbef321 2024-10-29)`
* and ` cargo 1.85.0-nightly (769f622e1 2024-12-14)`

* OS: Debian Trixie,
```bash
uname -a
Linux nevermore 6.11.9-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.11.9-1 (2024-11-17) x86_64 GNU/Linux
```

Adapter Info:

```
2025-01-24T23:44:49.673613Z INFO bevy_render::renderer: AdapterInfo { name: "Intel(R) Graphics (MTL)", vendor: 32902, device: 32069, device_type: IntegratedGpu, driver: "Intel open-source Mesa driver", driver_info: "Mesa 24.2.8-1", backend: Vulkan }
```

## What you did

1. Start with an example that has a UI, such as https://bevyengine.org/examples/games/game-menu/
2. Run it - it works and shows the Menu with the buttons
3. Add a system that adds a second camera at startup. Specify the camera order to avoid ambiguities and a marker type to distinguish it.

```rust
#[derive(Component)]
struct SillyCameraMarker{}

// System that sets up an inactive camera.
fn setup_inactive_camera(mut commands: Commands) {
// https://bevy-cheatbook.github.io/2d/camera.html
let camera = (
Camera2d,
SillyCameraMarker{},
Camera {
// higher order means rendered on top.
order: 2,
// clearcolor None to avoid hiding what the first camera shows.
clear_color: ClearColorConfig::None,
// TODO: Bug in bevy?: is_active:false disables my main menu.
is_active: true,
..default()
},
);

commands.spawn((
camera,
));
}

```
5. Add the system to `game::game_plugin()`:
```rust
app.add_systems(Startup, crate::setup_inactive_camera);
```
6. Run it. Everything still works. This means to me that setting the `clear_color` works. (But maybe I misunderstood something there. Because if I don't specify the `ClearColorConfig::None`, the active camera does not hide the content either)
7. Change `is_active` to `false` instead of `true`.
8. Run it. There is just a blank screen, no Buttons.
9. Change the camera order of the first camera to 4, so it is now in front of our newly-added inactive camera.
10. The buttons show up again!

This all seems complex enough to probably be a beginner's mistake..., but then I would expect the active camera to also break the menu.

I can explicitly specify the `RenderLayers` as a separate layer, such as `3`, but that does not change anything: The active camera still keeps everything working, the inactive camera still breaks the menu.

## What went wrong

### what were you expecting?
That the Menu Buttons are not affected by a second camera which is set to inactive and has `clear_color: ClearColorConfig::None`.

### what actually happened?
The second camera breaks the menu if I set it to inactive.

## Additional information

Perhaps this is related:

* https://github.com/bevyengine/bevy/issues/11377
> The actual API will not return a warn or something, it will almost randomly pick one of the cameras. The camera depends on the camera order, the line is as follow

* https://github.com/bevyengine/bevy/issues/17530
* That issue was also opened by me and it also has to do with a second camera. So if this is a mistake on my part, so might be the other issue.

I am attaching the code I used for reproducing this. The problematic `is_active` is on line 785.

[mainmenucam.zip](https://github.com/user-attachments/files/18550921/mainmenucam.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.