Sprite z-order is wrong when parent entity has no Transform.
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.
The given example code will now produce a warning since #5590 was merged
@StarArawn - is this still a problem?
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.
should this be kept open or can we consider it resolved?
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:
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.
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.