-
-
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
Allow spawning top-level entities from ChildBuilder #8812
Comments
Comments in PR #2448 raise concerns about how it might be confusing to have a
What name(s) would you suggest?
(* same for |
Could you give more specific examples of what you would want to do with "top level" commands? |
For example, to emulate tabs I mark my tab-buttons with fn setup_system(mut commands: Commands, mut tab_commands: Commands) {
commands
.spawn((
NodeBundle {
style: Style {
flex_direction: FlexDirection::Column,
size: Size::all(Val::Percent(100.0)),
..Default::default()
},
..Default::default()
},
UiRoot,
))
.with_children(|parent| {
// Stores tab buttons.
let tabs_entity = parent
.spawn(NodeBundle {
style: Style {
justify_content: JustifyContent::Center,
..Default::default()
},
..Default::default()
})
.id();
for (index, tab) in SettingsTab::iter().enumerate() {
let content_entity = parent
.spawn(NodeBundle::default())
.with_children(|parent| {
// Spawn tab content depending on tab
})
.id();
// Spawn button for the tab.
tab_commands
.spawn((
TabContent(content_entity),
ExclusiveButton,
Pressed(index == 0),
ButtonBundle::default(),
))
.set_parent(tabs_entity);
}
});
} |
Another use case. I need to get an entity for my parent
.spawn(NodeBundle {
style: Style {
size: Size::new(Val::Percent(50.0), Val::Percent(30.0)),
..Default::default()
},
..Default::default()
})
.with_children(|parent| {
let label_entity = label_commands.spawn(LabelBundle::large(theme, label)).id();
parent
.spawn(NodeBundle {
style: Style {
size: Size::all(Val::Percent(100.0)),
..Default::default()
},
..Default::default()
})
.add_child(label_entity);
parent.spawn((button, LabelEntity(label_entity), ButtonBundle::default()));
}); |
What problem does this solve or what need does it fill?
Sometimes you need to access to commands in order to spawn a top-level entity inside
with_children
to assign its parent later. I found it very useful forbevy_ui
because the hierarchy could be very deep and there is no way to access commands in inner levels.This was addressed #2817, but it was closed in favor of
add_children
from #4708, butadd_children
was removed in #6942.What solution would you like?
Add a method to
ChildBuilder
that allow spawning entities outside of hierarchy.What alternative(s) have you considered?
We could to consider re-opening #2817. It's a very small change.
The text was updated successfully, but these errors were encountered: