Skip to content
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

Missing a method to insert related entities at a specific index (insert_children) #17478

Open
villor opened this issue Jan 21, 2025 · 0 comments
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Milestone

Comments

@villor
Copy link
Contributor

villor commented Jan 21, 2025

What problem does this solve or what need does it fill?

Before #17398 there was a pretty handy method for inserting a slice of children at a specific index: insert_children

Not sure if it was intentionally left out, or just lost in the process. It's pretty useful for UI sometimes when needing to insert one or more children in specific spots.

While migrating bevy_editor_prototypes I resorted to an extension for now:

impl InsertChildrenExt for EntityWorldMut<'_> {
    fn insert_children(&mut self, index: usize, children: &[Entity]) {
        let prev_children = self.take::<Children>().unwrap_or_default();
        let (prev_left, prev_right) = prev_children.split_at(index);

        let parent_id = self.id();
        self.world_scope(|world| {
            for child in prev_left.iter().chain(children).chain(prev_right) {
                world.entity_mut(*child).insert(ChildOf(parent_id));
            }
        });
    }
}

What solution would you like?

  • Add insert_related method on EntityWorldMut/EntityCommands, inserting a &[Entity] (or iterator?) at a specific index.
  • Add insert_children for convenience and less breakage when migrating

What alternative(s) have you considered?

  • Could just skip it and let "user-space" handle it like the extension above or similar. But seeing as it was in there before, I guess at some point it was deemed useful enough to keep upstream.
@villor villor added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Jan 21, 2025
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Jan 21, 2025
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! and removed S-Needs-Triage This issue needs to be labelled C-Feature A new feature, making something new possible labels Jan 21, 2025
@BenjaminBrienen BenjaminBrienen added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

No branches or pull requests

3 participants