bevy/crates/bevy_ecs/src
Carter Anderson d8fa57bd7b
Switch ChildOf back to tuple struct (#18672)
# Objective

In #17905 we swapped to a named field on `ChildOf` to help resolve
variable naming ambiguity of child vs parent (ex: `child_of.parent`
clearly reads as "I am accessing the parent of the child_of
relationship", whereas `child_of.0` is less clear).

Unfortunately this has the side effect of making initialization less
ideal. `ChildOf { parent }` reads just as well as `ChildOf(parent)`, but
`ChildOf { parent: root }` doesn't read nearly as well as
`ChildOf(root)`.

## Solution

Move back to `ChildOf(pub Entity)` but add a `child_of.parent()`
function and use it for all accesses. The downside here is that users
are no longer "forced" to access the parent field with `parent`
nomenclature, but I think this strikes the right balance.

Take a look at the diff. I think the results provide strong evidence for
this change. Initialization has the benefit of reading much better _and_
of taking up significantly less space, as many lines go from 3 to 1, and
we're cutting out a bunch of syntax in some cases.

Sadly I do think this should land in 0.16 as the cost of doing this
_after_ the relationships migration is high.
2025-04-02 00:10:10 +00:00
..
entity Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
error Use Display instead of Debug in the default error handler (#18629) 2025-03-31 18:28:19 +00:00
event bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
identifier bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
observer reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
query Get names of queued components (#18451) 2025-03-31 23:22:33 +00:00
reflect Replace VisitEntities with MapEntities (#18432) 2025-03-21 00:18:10 +00:00
relationship Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
schedule Get names of queued components (#18451) 2025-03-31 23:22:33 +00:00
storage Fix lint errors on bevy_ecs with disabled features (#18488) 2025-03-22 16:36:56 +00:00
system Include SystemParamValidationError in RunSystemError and RegisteredSystemError (#18666) 2025-04-01 19:27:08 +00:00
world Get names of queued components (#18451) 2025-03-31 23:22:33 +00:00
archetype.rs Fix clippy::let_and_return in bevy_ecs (#18481) 2025-03-22 11:48:40 +00:00
batching.rs Fix *most* clippy lints (#15906) 2024-10-14 20:52:35 +00:00
bundle.rs Fix clippy::let_and_return in bevy_ecs (#18481) 2025-03-22 11:48:40 +00:00
change_detection.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
component.rs Get names of queued components (#18451) 2025-03-31 23:22:33 +00:00
entity_disabling.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
hierarchy.rs Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
intern.rs Move hashbrown and foldhash out of bevy_utils (#17460) 2025-01-23 16:46:08 +00:00
label.rs do_not_recommend interned Labels (#17950) 2025-02-25 23:46:21 +00:00
lib.rs Rename EntityBorrow/TrustedEntityBorrow to ContainsEntity/EntityEquivalent (#18470) 2025-03-30 06:04:26 +00:00
name.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
removal_detection.rs bevy_reflect: Add clone registrations project-wide (#18307) 2025-03-17 18:32:35 +00:00
resource.rs Move Resource trait to its own file (#17469) 2025-01-21 19:47:08 +00:00
spawn.rs Implement SpawnableList for Vec<Bundle> (#18259) 2025-03-11 20:32:37 +00:00
traversal.rs Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00