Skip to content

Unstable z-order sorting when using multiple root UI nodes #2569

Closed
@alice-i-cecile

Description

@alice-i-cecile

Bevy version

0.5

Operating system & version

Windows 10

What you did

pub use bevy::prelude::*;

pub struct Tooltips;

pub fn test_square(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
    commands
        .spawn_bundle(NodeBundle {  // blue square
            style: Style {
                size: Size::new(Val::Px(200.0), Val::Px(200.0)),
                position_type: PositionType::Absolute,
                ..Default::default()
            },
            material: materials.add(Color::rgb(0.4, 0.4, 1.0).into()),
            ..Default::default()
        })
        //.insert(Tooltips)  // WHEN THIS LINE IS ON, THE TEST SQUARE DOES NOT SHOW UP
        ;
}

pub fn spawn_hud(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
    commands.spawn_bundle(UiCameraBundle::default());

    commands
        /* ui root node */
        .spawn_bundle(NodeBundle {
            style: Style {
                size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
                ..Default::default()
            },
            material: materials.add(Color::rgba_u8(0, 0, 0, 0).into()),
            ..Default::default()
        })
        .with_children(|parent| {
            parent.spawn_bundle(NodeBundle {
                material: materials.add(Color::BLACK.into()),
                ..Default::default()
            });
        });
}

pub fn main() {
    App::build()
    
        .insert_resource(ClearColor(Color::rgb_u8(10, 10, 10)))
        .insert_resource(WindowDescriptor {
            width: (32. * 20.),
            height: (32. * 15.),
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_startup_system(spawn_hud.system())
        .add_startup_system(test_square.system())
        .run();
}

What you expected to happen

The square appears, or doesn't.

What actually happened

Adding the marker component to the entity changes the relative order of the square and the HUD, causing the square to disappear.
Removing or tweaking most of the other values (window size, clear_color, presence of the child on the HUD) also tends to change the behavior. Altering colors or changing the square's size seems to preserve the surprising behavior.

Additional information

Using multiple root UI nodes is currently (silently) unsupported; this . I think this is z-fighting in very unstable and surprising ways. #1211 attempts to allow for multiple UI root nodes.

@automeowtion on Discord reported this bug and gave the reproduction shown above here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenA-UIGraphical user interfaces, styles, layouts, and widgetsC-BugAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions