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

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

Closed
alice-i-cecile opened this issue Jul 30, 2021 · 6 comments
Closed

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

alice-i-cecile opened this issue Jul 30, 2021 · 6 comments
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong

Comments

@alice-i-cecile
Copy link
Member

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.

@alice-i-cecile alice-i-cecile 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-Rendering Drawing game state to the screen S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Jul 30, 2021
@alice-i-cecile
Copy link
Member Author

For the most part, I think this should just be solved by allowing for multiple UI root nodes in a sensible way. Or loudly complaining when a user attempts to do so.

Z-fighting in general could probably use a warning of some sort, but I'm not sure how that should be done.

@Davier
Copy link
Contributor

Davier commented Jul 30, 2021

I'd be happy to revive #1211 if there is enough interest to merge it

@alice-i-cecile
Copy link
Member Author

I'd be happy to revive #1211 if there is enough interest to merge it

Yeah, we should sit down and cohesively discuss what we want to do with parent/child mess and UI in the short-term. @cart when and where would you prefer that conversation happen?

@cart
Copy link
Member

cart commented Jul 30, 2021

Hmm this should probably be a discussion first outlining the current situation. Then we can discuss solutions and hopefully agree on one that makes sense.

@james7132
Copy link
Member

Is this still an issue after #5877?

@alice-i-cecile
Copy link
Member Author

Nope, I'm happy to call this resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-UI Graphical user interfaces, styles, layouts, and widgets C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

No branches or pull requests

4 participants