Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI nodes should ignore RenderLayers #17400

Open
ickshonpe opened this issue Jan 16, 2025 · 1 comment · May be fixed by #17405
Open

UI nodes should ignore RenderLayers #17400

ickshonpe opened this issue Jan 16, 2025 · 1 comment · May be fixed by #17405
Labels
A-Reflection Runtime information about types A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior

Comments

@ickshonpe
Copy link
Contributor

ickshonpe commented Jan 16, 2025

Bevy version

Bevy main

What you did

Added RenderLayers::layer(1) to the text entities in the multiple_windows example.

//! Uses two windows to visualize a 3D model from different angles.

use bevy::{prelude::*, render::camera::RenderTarget, window::WindowRef};
use bevy_render::view::RenderLayers;

fn main() {
    App::new()
        // By default, a primary window gets spawned by `WindowPlugin`, contained in `DefaultPlugins`
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup_scene)
        .run();
}

fn setup_scene(mut commands: Commands, asset_server: Res<AssetServer>) {
    // add entities to the world
    commands.spawn(SceneRoot(
        asset_server.load(GltfAssetLabel::Scene(0).from_asset("models/torus/torus.gltf")),
    ));
    // light
    commands.spawn((
        DirectionalLight::default(),
        Transform::from_xyz(3.0, 3.0, 3.0).looking_at(Vec3::ZERO, Vec3::Y),
    ));

    let first_window_camera = commands
        .spawn((
            Camera3d::default(),
            Transform::from_xyz(0.0, 0.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
        ))
        .id();

    // Spawn a second window
    let second_window = commands
        .spawn(Window {
            title: "Second window".to_owned(),
            ..default()
        })
        .id();

    let second_window_camera = commands
        .spawn((
            Camera3d::default(),
            Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
            Camera {
                target: RenderTarget::Window(WindowRef::Entity(second_window)),
                ..default()
            },
        ))
        .id();

    let node = Node {
        position_type: PositionType::Absolute,
        top: Val::Px(12.0),
        left: Val::Px(12.0),
        ..default()
    };

    commands.spawn((
        Text::new("First window"),
        node.clone(),
        // Since we are using multiple cameras, we need to specify which camera UI should be rendered to
        TargetCamera(first_window_camera),
        RenderLayers::layer(1),
    ));

    commands.spawn((
        Text::new("Second window"),
        node,
        TargetCamera(second_window_camera),
        RenderLayers::layer(1),
    ));
}

What went wrong

The text labels are not visible.

Additional information

The UI doesn't use Renderlayers instead you set a target camera using the TargetCamera component.

The example above doesn't seem that terrible. The cameras are using render layer 0, so it makes sense they wouldn't display UI nodes using render layer 1.

But if you set the second camera to render layer 1 and remove the TargetCamera from the second text entity both text nodes are now rendered to camera 1 on top of each other. And if you then remove the second camera, the second text node goes invisible. Which all seems like nonsense.

@ickshonpe ickshonpe added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled A-UI Graphical user interfaces, styles, layouts, and widgets A-Reflection Runtime information about types and removed S-Needs-Triage This issue needs to be labelled labels Jan 16, 2025
@ickshonpe ickshonpe changed the title UI entities aren't visible unless they belong to render layer 0 UI nodes should ignore RenderLayers Jan 16, 2025
@ickshonpe ickshonpe linked a pull request Jan 16, 2025 that will close this issue
@alice-i-cecile
Copy link
Member

See #17402.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants