bevyengine / bevyengine/bevy

Move methods on `Children` that mutate to `EntityCommands`

Open
#15,270 1 comment 0 reactions 0 assignees View on GitHub
A-ECS C-Code-Quality D-Straightforward S-Needs-Design X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

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

All of our hierarchy management controls happen through `Command`s, *except* methods of sorting children for a given entity. These methods should be changed to `Command`s like the rest of the hierarchy management. This might be required when changing `Children` to a relation, anyways.

## What solution would you like?

Replace the following methods with commands:
- [`Children::swap`](https://docs.rs/bevy/0.14.0/bevy/hierarchy/struct.Children.html#method.swap)
- [`Children::sort_by`](https://docs.rs/bevy/0.14.0/bevy/hierarchy/struct.Children.html#method.sort_by)
- [`Children::sort_by_key`](https://docs.rs/bevy/0.14.0/bevy/hierarchy/struct.Children.html#method.sort_by_key)
- [`Children::sort_by_cached_key`](https://docs.rs/bevy/0.14.0/bevy/hierarchy/struct.Children.html#method.sort_by_cached_key)
- [`Children::sort_unstable_by`](https://docs.rs/bevy/0.14.0/bevy/hierarchy/struct.Children.html#method.sort_unstable_by)
- [`Children::sort_unstable_by_key`](https://docs.rs/bevy/0.14.0/bevy/hierarchy/struct.Children.html#method.sort_unstable_by_key)

Ideally:
```rust
impl EntityCommands {
pub fn sort_children_by(&mut self, compare: impl FnMut(Entity, Entity) -> Ordering) -> &mut Self;
pub fn sort_children_by_key(&mut self, compare: impl FnMut(Entity) -> K) -> &mut Self;
// etc...
}
```

Contributor guide

Open the contributing guide

Research direction

Start by locating the Children and EntityCommands definitions and the six listed mutating methods. Trace how hierarchy commands are implemented, then replace the Children sorting methods with corresponding EntityCommands commands while preserving their stated sorting behavior; done means all six operations are available through commands instead.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.