bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Sprite z-order is wrong when parent entity has no Transform.

Open StarArawn opened this issue 4 years ago • 5 comments

Bevy version

0.5

Operating system & version

Windows 10

What you did

Create a sprite like:

commands
        .spawn()
        .insert(Enemy::default())
        .with_children(|child_builder| {
            let texture_handle: Handle<Texture> = asset_server.load("textures/spider_sprite.png");
            let enemy_sprite_material = materials.add(texture_handle.into());
            child_builder    
                .spawn_bundle(SpriteBundle {
                    material: enemy_sprite_material,
                    transform: Transform::from_xyz(position.x, position.y, 10.0),
                    ..Default::default()
                })
                .insert(RenderLayers::layer(0));
        })

Have another sprite that is suppose to render behind and you can see how the sprites z values on the GPU are completely wrong.

With a sprite that has no parent the calculated z values are: .9980 and with a sprite that has a parent without a transform: -0.001

What you expected to happen

If a parent entity has no transform its children's transforms should not change.

StarArawn avatar Apr 21 '21 22:04 StarArawn

The given example code will now produce a warning since #5590 was merged

tim-blackbird avatar Dec 09 '22 20:12 tim-blackbird

@StarArawn - is this still a problem?

superdump avatar Jan 31 '23 09:01 superdump

It is "fixed" by #5590 in the sense that it now displays a warning that tells the user why the transform is not applied, and allow them to fix it themselves.

nicopap avatar Jan 31 '23 10:01 nicopap

should this be kept open or can we consider it resolved?

nicopap avatar Apr 18 '23 08:04 nicopap

Triage

Behavior is unchanged with Bevy 0.12.

Reproduction code: https://github.com/TimJentzsch/bevy_triage/tree/main/issues/issue_1976

In this example we spawn a yellow rectangle at the bottom, a red rectangle in the middle, but with a parent element which doesn't have a transform, and a blue rectangle at the top. Instead, the red rectangle is at the bottom: Red rectangle at the bottom, then yellow, then blue at the top

However, we get the following warnings in the console:

2024-01-25T19:44:31.856051Z  WARN bevy_hierarchy::valid_parent_check_plugin: warning[B0004]: An entity with the InheritedVisibility component has a parent without InheritedVisibility.
This will cause inconsistent behaviors! See https://bevyengine.org/learn/errors/#b0004
2024-01-25T19:44:31.856091Z  WARN bevy_hierarchy::valid_parent_check_plugin: warning[B0004]: An entity with the GlobalTransform component has a parent without GlobalTransform.
This will cause inconsistent behaviors! See https://bevyengine.org/learn/errors/#b0004

Considering that there is even an error code with a more detailed explanation, I think we could consider this resolved for now. I will defer for other maintainers to make this decision though.

TimJentzsch avatar Jan 25 '24 19:01 TimJentzsch

Since we can always reopen this in the future, I'm closing this as completed based on the fact that we have these warnings now.

mnmaita avatar Jun 03 '24 21:06 mnmaita