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

Tagging ImageBundle makes it disappear #1329

Closed
smokku opened this issue Jan 27, 2021 · 6 comments
Closed

Tagging ImageBundle makes it disappear #1329

smokku opened this issue Jan 27, 2021 · 6 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@smokku
Copy link
Member

smokku commented Jan 27, 2021

  • Bevy version: 0.4
  • Operating system: Windows 10

I am building an UI and have an absolutely positioned image using ImageBundle. It works until I add an additional component to it (no matter empty or not) - image then disappears.

        .spawn(ImageBundle {
            style: Style {
                size: Size::new(Val::Px(25.0), Val::Px(25.0)),
                position_type: PositionType::Absolute,
                position: Rect {
                    left: Val::Px(10.0),
                    bottom: Val::Px(10.0),
                    ..Default::default()
                },
                ..Default::default()
            },
            material: materials.add(asset_server.load("crosshairs/crosshair026.png").into()),
            ..Default::default()
        })
        .with(control::MouseCursor)

The same code, but with TextBundle works as expected.

@Davier
Copy link
Contributor

Davier commented Jan 27, 2021

I was not able to reproduce using this code with current master branch:

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(test.system())
        .run();
}

struct Test;

fn test(commands: &mut Commands, mut materials: ResMut<Assets<ColorMaterial>>, asset_server: Res<AssetServer>) {
    commands.spawn(CameraUiBundle::default());
    commands.spawn(ImageBundle {
            style: Style {
                size: Size::new(Val::Px(25.0), Val::Px(25.0)),
                position_type: PositionType::Absolute,
                position: Rect {
                    left: Val::Px(10.0),
                    bottom: Val::Px(10.0),
                    ..Default::default()
                },
                ..Default::default()
            },
            material: materials.add(asset_server.load("test.png").into()),
            ..Default::default()
        }).with(Test);
}

Could you give more details?

@smokku
Copy link
Member Author

smokku commented Jan 27, 2021

Updating to master didn't help.
So, I started stripping my app to the base minimum reproducible code.

This code:

use bevy::prelude::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_startup_system(test.system())
        .run();
}

struct Test;

fn test(
    commands: &mut Commands,
    mut materials: ResMut<Assets<ColorMaterial>>,
    asset_server: Res<AssetServer>,
) {
    commands
        .spawn(CameraUiBundle::default())
        .spawn(NodeBundle {
            style: Style {
                size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
                position_type: PositionType::Absolute,
                justify_content: JustifyContent::Center,
                align_items: AlignItems::Center,
                ..Default::default()
            },
            material: materials.add(Color::NONE.into()),
            ..Default::default()
        })
        .with_children(|parent| {
            // bevy logo (image)
            parent.spawn(ImageBundle {
                style: Style {
                    size: Size::new(Val::Px(50.0), Val::Px(50.0)),
                    ..Default::default()
                },
                material: materials.add(asset_server.load("icon.png").into()),
                ..Default::default()
            });
        })
        .spawn(ImageBundle {
            style: Style {
                size: Size::new(Val::Px(50.0), Val::Px(50.0)),
                position_type: PositionType::Absolute,
                position: Rect {
                    left: Val::Px(110.0),
                    bottom: Val::Px(10.0),
                    ..Default::default()
                },
                ..Default::default()
            },
            material: materials.add(asset_server.load("icon.png").into()),
            ..Default::default()
        })
        // .with(Test)
        ;
}

renders:
image

After uncommenting .with(Test) I get:

image

@DJMcNab
Copy link
Member

DJMcNab commented Jan 27, 2021

I can reproduce. I'll try doing some debugging steps

@DJMcNab
Copy link
Member

DJMcNab commented Jan 27, 2021

Yeah, so the bug is that the ImageBundle is closer than the near plane of the CameraUIBundle. Not sure how to fix it - I'm not an expert in the UI system.

@Davier
Copy link
Contributor

Davier commented Jan 28, 2021

The issue is that the NodeBundle somehow hides the second ImageBundle. Adding/removing the extra component would change the iteration order in some systems, and since both are on the same z plane the one drawn in front in unspecified. However Color::None is supposed to be transparent, and both icons show up when setting is_visible to false on the NodeBundle. So I believe there is a bug when drawing transparent materials that are in the same z plane. (something like #1211 could help in the future by making it impossible to happen).
I'm not familiar with the drawing/rendering part of bevy yet, so I'm not sure how to fix it.

@karroffel karroffel added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Jan 30, 2021
@smokku smokku changed the title Tagging ImageBundle does not work Tagging ImageBundle makes it disappear Jan 30, 2021
@rparrett
Copy link
Contributor

rparrett commented Jan 10, 2023

I can't reproduce this, since at least Bevy 0.6 at which point it's starting to get painful to test.

The last comment seems to be alluding to an underlying bug that I think should have been fixed by #5877 though.

Happy to reopen this if it turns out that's not the case.

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 C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

5 participants