-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - Fix inconsistent children removal behavior #6017
Conversation
I updated this PR to reflect the latest discussion in the referenced issue. This is ready for a review, but before merging I will need to go over the bevy_ui flex system and bevy_transform propagation system to make sure that they work expectedly, and possibly add |
I think that there shouldn't be an issue with transform propagation, but there there's definitely an issue with UI. Tested with this, derived from the ui example. Pressing space moves the yellow box from the left to the right side of the screen. With this PR, the green container on the left side isn't properly updated and stays at its previous size despite having been emptied. use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup)
.add_system(detach)
.run();
}
#[derive(Component)]
struct Destination;
#[derive(Component)]
struct Source;
fn detach(
mut commands: Commands,
input: Res<Input<KeyCode>>,
query: Query<(Entity, &Children), With<Source>>,
dest_query: Query<Entity, With<Destination>>,
) {
if input.just_pressed(KeyCode::Space) {
let (source_entity, children) = query.single();
let dest_entity = dest_query.single();
commands.entity(source_entity).remove_children(children);
commands.entity(dest_entity).push_children(children);
}
}
fn setup(mut commands: Commands) {
commands.spawn_bundle(Camera2dBundle::default());
commands
.spawn_bundle(NodeBundle {
style: Style {
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
justify_content: JustifyContent::SpaceBetween,
..default()
},
color: Color::NONE.into(),
..default()
})
.with_children(|parent| {
parent
.spawn_bundle(NodeBundle {
style: Style {
size: Size::new(Val::Percent(50.0), Val::Undefined),
..default()
},
color: Color::GREEN.into(),
..default()
})
.insert(Source)
.with_children(|parent| {
parent.spawn_bundle(NodeBundle {
style: Style {
size: Size::new(Val::Percent(100.0), Val::Px(100.0)),
..default()
},
color: Color::YELLOW.into(),
..default()
});
});
parent
.spawn_bundle(NodeBundle {
style: Style {
size: Size::new(Val::Percent(50.0), Val::Undefined),
..default()
},
color: Color::RED.into(),
..default()
})
.insert(Destination);
});
} |
The issue with UI is that the for entity in &removed_children {
if let Some(&node) = flex_surface.entity_to_taffy.get(&entity) {
flex_surface.taffy.set_children(node, &[]).unwrap();
}
} seems to solve the issue. |
My latest commit should fix the UI flex system. Thanks for the info 👍 @devil-ira Have you tested the |
The issue with UI is that taffy has a copy of the hierarchy that needs to be kept up to date and that children can affect the parent. Neither of those apply to transforms, so it should be good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from one thing.
bors r+ |
# Objective Fixes #6010 ## Solution As discussed in #6010, this makes it so the `Children` component is removed from the entity whenever all of its children are removed. The behavior is now consistent between all of the commands that may remove children from a parent, and this is tested via two new test functions (one for world functions and one for commands). Documentation was also added to `insert_children`, `push_children`, `add_child` and `remove_children` commands to make this behavior clearer for users. ## Changelog - Fixed `Children` component not getting removed from entity when all its children are moved to a new parent. ## Migration Guide - Queries with `Changed<Children>` will no longer match entities that had all of their children removed using `remove_children`. - `RemovedComponents<Children>` will now contain entities that had all of their children remove using `remove_children`.
Pull request successfully merged into main. Build succeeded: |
# Objective Fixes bevyengine#6010 ## Solution As discussed in bevyengine#6010, this makes it so the `Children` component is removed from the entity whenever all of its children are removed. The behavior is now consistent between all of the commands that may remove children from a parent, and this is tested via two new test functions (one for world functions and one for commands). Documentation was also added to `insert_children`, `push_children`, `add_child` and `remove_children` commands to make this behavior clearer for users. ## Changelog - Fixed `Children` component not getting removed from entity when all its children are moved to a new parent. ## Migration Guide - Queries with `Changed<Children>` will no longer match entities that had all of their children removed using `remove_children`. - `RemovedComponents<Children>` will now contain entities that had all of their children remove using `remove_children`.
# Objective Fixes bevyengine#6010 ## Solution As discussed in bevyengine#6010, this makes it so the `Children` component is removed from the entity whenever all of its children are removed. The behavior is now consistent between all of the commands that may remove children from a parent, and this is tested via two new test functions (one for world functions and one for commands). Documentation was also added to `insert_children`, `push_children`, `add_child` and `remove_children` commands to make this behavior clearer for users. ## Changelog - Fixed `Children` component not getting removed from entity when all its children are moved to a new parent. ## Migration Guide - Queries with `Changed<Children>` will no longer match entities that had all of their children removed using `remove_children`. - `RemovedComponents<Children>` will now contain entities that had all of their children remove using `remove_children`.
# Objective Fixes bevyengine#6010 ## Solution As discussed in bevyengine#6010, this makes it so the `Children` component is removed from the entity whenever all of its children are removed. The behavior is now consistent between all of the commands that may remove children from a parent, and this is tested via two new test functions (one for world functions and one for commands). Documentation was also added to `insert_children`, `push_children`, `add_child` and `remove_children` commands to make this behavior clearer for users. ## Changelog - Fixed `Children` component not getting removed from entity when all its children are moved to a new parent. ## Migration Guide - Queries with `Changed<Children>` will no longer match entities that had all of their children removed using `remove_children`. - `RemovedComponents<Children>` will now contain entities that had all of their children remove using `remove_children`.
I am not sure this is the right place to give feedback, but... I have run into a problem that I can certainly solved myself, but feels like I should mention it:
|
This is a little strange, see bevyengine/bevy#6017 (comment)
# Objective Fixes bevyengine#6010 ## Solution As discussed in bevyengine#6010, this makes it so the `Children` component is removed from the entity whenever all of its children are removed. The behavior is now consistent between all of the commands that may remove children from a parent, and this is tested via two new test functions (one for world functions and one for commands). Documentation was also added to `insert_children`, `push_children`, `add_child` and `remove_children` commands to make this behavior clearer for users. ## Changelog - Fixed `Children` component not getting removed from entity when all its children are moved to a new parent. ## Migration Guide - Queries with `Changed<Children>` will no longer match entities that had all of their children removed using `remove_children`. - `RemovedComponents<Children>` will now contain entities that had all of their children remove using `remove_children`.
Objective
Fixes #6010
Solution
As discussed in #6010, this makes it so the
Children
component is removed from the entity whenever all of its children are removed. The behavior is now consistent between all of the commands that may remove children from a parent, and this is tested via two new test functions (one for world functions and one for commands).Documentation was also added to
insert_children
,push_children
,add_child
andremove_children
commands to make this behavior clearer for users.Changelog
Children
component not getting removed from entity when all its children are moved to a new parent.Migration Guide
Changed<Children>
will no longer match entities that had all of their children removed usingremove_children
.RemovedComponents<Children>
will now contain entities that had all of their children remove usingremove_children
.