`InheritedVisibility` not updated when `Parent` changes
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version
v0.13.0 (and v0.12.1)
## What you did
Move an `Visibility::Inherited` child entity from a parent with `Visibility::Visible` to a different parent with`Visibility::Hidden` does not change the `InheritedVisibility` of the child entity when `App::update()` runs.
```rs
use bevy::{
prelude::*,
render::{deterministic::DeterministicRenderingConfig, view::VisibilityPlugin},
};
fn main() {
let mut app = App::new();
// add the VisibilityPlugin, and required resources
app.add_plugins(VisibilityPlugin)
.insert_resource(Assets::::default())
.insert_resource(DeterministicRenderingConfig::default());
// create two parents, one visibile and one hidden
let visible_parent = app
.world
.spawn((
Name::new("visible parent"),
SpatialBundle {
visibility: Visibility::Visible,
..default()
},
))
.id();
let hidden_parent = app
.world
.spawn((
Name::new("hidden parent"),
SpatialBundle {
visibility: Visibility::Hidden,
..default()
},
))
.id();
// create a child under the visibile parent
let child = app
.world
.spawn((
Name::new("child"),
SpatialBundle {
visibility: Visibility::Inherited,
..default()
},
))
.set_parent(visible_parent)
.id();
// run app.update and confirm that the child's InheritedVisibility is true
app.update();
assert!(
app.world
.get::(child)
.expect("ran app.update with Visibility on child")
.get(),
"child should be hidden as parent is hidden parent: {:?}",
app.world.get::(child)
);
// move the child entity under the hidden parent & run all systems again
app.world.entity_mut(child).set_parent(hidden_parent);
app.update();
// child should now be hidden, but this assertion fails on v0.13.0
assert!(
!app.world
.get::(child)
.expect("ran app.update with Visibility on child")
.get(),
"child should be hidden as parent is hidden parent: {:?}",
app.world.get::(child)
);
}
```
## What went wrong
We fail the test case above because after moving the `Visibility::Inherited` child under a `Visibility::Hidden` parent, the child's `InheritedVisibility` is `true`.
Contributor guide
Assessment
This issue has not been assessed yet.