bevy/crates
ira 0d606030a2 Remove EntityCommands::add_children (#6942)
# Objective
Remove a method with an unfortunate name and questionable usefulness.
Added in #4708

It doesn't make sense to me for us to provide a method to work around a limitation of closures when we can simply, *not* use a closure.
The limitation in this case is not being able to initialize a variable from inside a closure:

```rust
let child_id;
commands.spawn_empty().with_children(|parent| {
    // Error: passing uninitalized variable to a closure.
    child_id = parent.spawn_empty().id();
});

// Do something with child_id
```
The docs for `add_children` suggest the following:
```rust
let child_id = commands
    .spawn_empty()
    .add_children(|parent| parent.spawn_empty().id());
```
I would instead suggest using the following snippet.
```rust
let parent_id = commands.spawn_empty().id();
let child_id = commands.spawn_empty().set_parent(parent_id).id();

// To be fair, at the time of #4708 this would have been a bit more cumbersome since `set_parent` did not exist.
```

Using `add_children` gets more unwieldy when you also want the `parent_id`.
```rust
let parent_commands = commands.spawn_empty();
let parent_id = parent_commands.id();
let child_id = parent_commands.add_children(|parent| parent.spawn_empty().id());
```
### The name
I see why `add_children` is named that way, it's the non-builder variant of `with_children` so it kinda makes sense,
but now the method name situation for `add_child`, `add_children` and `push_children` is *rather* unfortunate.

Removing `add_children` and renaming `push_children` to `add_children` in one go is kinda bleh, but that way we end up with the matching methods `add_child` and `add_children`. 

Another reason to rename `push_children` is that it's trying to mimick the `Vec` api naming but fails because `push` is for single elements. I guess it should have been `extend_children_from_slice`, but lets not name it that :)

### Questions
~~Should `push_children` be renamed in this PR? This would make the migration guide easier to deal with.~~
Let's do that later.

Does anyone know of a way to do a simple text/regex search through all the github repos for usage of `add_children`?
That way we can have a better idea of how this will affect users. My guess is that usage of `add_children` is quite rare.

## Migration Guide
The method `add_children` on `EntityCommands` was removed.
If you were using `add_children` over `with_children` to return data out of the closure you can use `set_parent` or `add_child` to avoid the closure instead.

Co-authored-by: devil-ira <justthecooldude@gmail.com>
2022-12-16 19:53:23 +00:00
..
bevy_animation Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_app run clear trackers on render world (#6878) 2022-12-11 18:34:15 +00:00
bevy_asset Derive clone and debug for AssetPlugin (#6583) 2022-11-14 23:08:26 +00:00
bevy_audio document file formats for bytes field of AudioSource (#6619) 2022-12-11 18:10:02 +00:00
bevy_core Fix reflection for PathBuf and OsString (#6776) 2022-11-27 17:28:06 +00:00
bevy_core_pipeline Fix missing sRGB conversion for dithering non-HDR pipelines (#6707) 2022-11-22 15:55:50 +00:00
bevy_derive Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_diagnostic pin nightly to 2022-11-28 to fix miri (#6808) 2022-12-01 01:30:55 +00:00
bevy_dylib Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_dynamic_plugin Adapt path type of dynamically_load_plugin (#6734) 2022-12-05 23:39:43 +00:00
bevy_ecs Fix clippy lints and failed test with Rust 1.66 (#6945) 2022-12-15 18:05:15 +00:00
bevy_ecs_compile_fail_tests Fix clippy lints and failed test with Rust 1.66 (#6945) 2022-12-15 18:05:15 +00:00
bevy_encase_derive Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_gilrs Bump gilrs version to 0.10 (#6558) 2022-11-15 20:31:17 +00:00
bevy_gltf Intepret glTF colors as linear instead of sRGB (#6828) 2022-12-04 19:35:13 +00:00
bevy_hierarchy Remove EntityCommands::add_children (#6942) 2022-12-16 19:53:23 +00:00
bevy_input Avoid triggering change detection for inputs (#6847) 2022-12-11 18:22:09 +00:00
bevy_internal Update dead links in DefaultPlugins docs (#6695) 2022-11-21 20:12:31 +00:00
bevy_log Update tracing-chrome requirement from 0.6.0 to 0.7.0 (#6709) 2022-12-04 22:30:09 +00:00
bevy_macro_utils Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_math Improve code/comments for Ray::intersect_plane and its tests (#6823) 2022-12-05 22:49:06 +00:00
bevy_mikktspace Release 0.9.0 (#6568) 2022-11-12 20:01:29 +00:00
bevy_pbr ShaderDefVal: add an UInt option (#6881) 2022-12-07 23:10:27 +00:00
bevy_ptr Add safe constructors for untyped pointers Ptr and PtrMut (#6539) 2022-11-14 22:53:50 +00:00
bevy_reflect Add reflection support for VecDeque (#6831) 2022-12-11 18:22:08 +00:00
bevy_render Make AsBindGroup unsized (#6937) 2022-12-16 01:40:15 +00:00
bevy_scene Allow iterating over with EntityRef over the entire World (#6843) 2022-12-05 22:35:02 +00:00
bevy_sprite Add DrawFunctionsInternals::id() (#6745) 2022-11-28 13:54:13 +00:00
bevy_tasks Update concurrent-queue to 2.0 (#6538) 2022-12-13 21:00:43 +00:00
bevy_text Remove TextError::ExceedMaxTextAtlases(usize) variant (#6796) 2022-12-05 23:23:16 +00:00
bevy_time Update old docs from Timer (#6646) 2022-11-18 20:42:33 +00:00
bevy_transform Parallelized transform propagation (#4775) 2022-11-21 18:18:38 +00:00
bevy_ui Add set_if_neq method to DetectChanges trait (Rebased) (#6853) 2022-12-11 19:24:19 +00:00
bevy_utils Document remaining members of bevy_utils (#6897) 2022-12-11 18:46:42 +00:00
bevy_window Derive Reflect + FromReflect for window event types (#6235) 2022-12-09 01:20:44 +00:00
bevy_winit Fix set_cursor_grab_mode to try an alternative mode before giving an error (#6599) 2022-11-26 13:10:11 +00:00