Skip to content

Conversation

johannesvollmer
Copy link
Contributor

@johannesvollmer johannesvollmer commented Oct 8, 2025

Objective

Fixes #21329 - The naming of the clear_children function could be misunderstood, so we suggest to rename it.

The current clear_children function could be understood to despawn the children, which it does not do. To emphasize the difference between clear and despawn, we can rename clear to detach. So we arrive at the final naming of despawn and detach.

Solution

To improve this, we could rename clear_children to detach_children and all other clear/remove functions too. I also suggest to rename all remove_child* functions for the same reason.

This renaming resulted in a confict because two methods now had the same name:

  • detach_children(self), previously clear_children
  • detach_children(self, children: &[Entity]), previously remove_children

To solve this, I propose we rename the former to detach_all_children. This was chosen because it has the least impact, considering that all methods do take a slice of children, except this one.

Changing the insert_* and add_* functions should be discussed. I think there is less potential for confusion, because they require you to pass an existing entity. Therefore it should be clear that this does not spawn anything.

Note: The function ui_surface.try_remove_children has not been renamed.

Testing

Currently running the tests, but there are unrelated compile errors in wgpu-hal blocking me (I am on windows).
For this reason, this is a draft pull request. Feel free to provide feedback already, while I am trying to make the tests run.

Discussion

As proposed in this PR, this would be a breaking change and will likely affect a large number of downstream projects directly. If you think this should be handled differently, via a #[deprecated] flag, I can rework the code to do that.

Is there no documentation to update? The repo yielded no more search results than this.

does not rename ui_surface.try_remove_children.
rename remove_children to detach_all_children to avoid naming conflicts.
@alice-i-cecile alice-i-cecile added this to the 0.18 milestone Oct 8, 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 M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Oct 8, 2025
Copy link
Contributor

github-actions bot commented Oct 8, 2025

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes.

@johannesvollmer johannesvollmer changed the title Rename remove_child* to detach_child* Rename clear_child* to detach_child* Oct 8, 2025
@johannesvollmer johannesvollmer marked this pull request as ready for review October 9, 2025 20:51
@johannesvollmer
Copy link
Contributor Author

Decided to use the deprecation mechanism, because it was mentioned in the migration guide guide, and a lot of downstream projects will likely be affected.

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Oct 10, 2025
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you!

Copy link
Contributor

@janis-bhm janis-bhm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
Should this same change be applied to *_related methods that these methods specialise, too? I think the same rationale applies to them as well, but maybe that is for a follow up PR, so it shouldn't block this one.

@johannesvollmer
Copy link
Contributor Author

Also, the methods add, insert and replace are unchanged, which is not perfectly symmetrical with detach. Renaming them to attach, attach_at_index and re_attach respectively does not feel right. Fortunately, with these methods, there is also less chance of confusion, because they expect you to have entities at hand already. Only the delete method can be confusing. But as you said, that can be done in a follow up PR.

@alice-i-cecile alice-i-cecile removed the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Oct 13, 2025
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 13, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Oct 13, 2025
Merged via the queue into bevyengine:main with commit e15cc8b Oct 13, 2025
38 checks passed
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 M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clear_children vs. despawn_children: a beginner's trap

4 participants