bevyengine / bevyengine/bevy

NodeBundles don't show unless RenderLayer 0 is used by any camera, even when TargetCamera is specified.

Open
#16,297 0 comments 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
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

0.14.2

##Relevant system information

```ignore
2024-11-08T19:14:28.114096Z INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux 24.1.1 Manjaro Linux", kernel: "6.10.13-3-MANJARO", cpu: "AMD Ryzen 9 5950X 16-Core Processor", core_count: "16", memory: "31.3 GiB" }

2024-11-08T19:14:28.303228Z INFO bevy_render::renderer: AdapterInfo { name: "AMD Radeon RX 6700 XT (RADV NAVI22)", vendor: 4098, device: 29663, device_type: DiscreteGpu, driver: "radv", driver_info: "Mesa 24.2.4-arch1.0.1", backend: Vulkan }
```

## What you did

I arrived at the problem described, as I had decided to use the same values for camera order as render layers to simplify my personal project. I ran into this issue when I added a camera that renders to texture as RenderLayer 0 followed by main camera on layer 1 then a ui camera on render layer 2. The first camera that renders to a texture is only created sometimes during run time given certain conditions. This leads to the button sometimes being present and sometimes not, eventually I found out that when I did not have any cameras rendering to texture the UI nodes would not render. (Although do note egui was still rendering correctly).

From here, I tried multiple different combinations of camera order and render layers; eventually I found out that if ANY camera is on RenderLayer 0, the UI would show up as expect on the correct TargetCamera regardless of what camera was set to render layer 0.

I have a simplified example linked below, where currently it is setup so the main camera is on render layer 1 and the ui camera is on render layer 2 and you will not see any buttons on screen.

If you then set the either MAIN_RENDER_LAYER or UI_RENDER_LAYER consts to 0 then the "Play Card" button will show up.
Or if you create a camera with default values and RenderLayer 0 set, the button will also show up, which can be seen by setting SPAWN_DUMMY_RENDER_LAYER_0_CAMERA to true.
For certainty, that it wasn't just drawing on the camera that was added on screen, I made the dummy camera render to a texture that is never used, so if the UI was in fact being rendered to this dummy camera we should still would not see the UI but the button does appear when enabled, thus concluding that the Button is being rendered to the UI camera and not the camera on Render Layer 0.

I did also try setting the RenderLayer of the NodeBundle itself to match the UI camera and as expected this doesn't work either.

[ExampleCode](https://github.com/Owlkaline/BevyUiRenderLayerBug/blob/main/src/main.rs)

## What went wrong

Expected:
```
UI to be visible even when a camera isn't set to RenderLayer 0.
```
Actual:
```
UI does not get drawn if there are no cameras on RenderLayer 0.
```

## Additional information

I have not found a work around yet in my own project, as for some reason the gltf scene renders on the lowest value renderlayer when it's renderlayer is set to one that doesn't exist on a camera.

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction in the linked repository's src/main.rs, using the MAIN_RENDER_LAYER, UI_RENDER_LAYER, and SPAWN_DUMMY_RENDER_LAYER_0_CAMERA settings to reproduce the missing buttons. Trace the NodeBundle, RenderLayer, and TargetCamera behavior during UI rendering. Done means the UI remains visible on its specified TargetCamera when no camera uses RenderLayer 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.