bevy/crates/bevy_ecs/src
Eagster 1966e44400
EntityGeneration ordering (#19421)
# Objective

Recently the `u32` `Entity::generation` was replaced with the new
`EntityGeneration` in #19121.
This made meanings a lot more clear, and prevented accidental misuse.

One common misuse was assuming that `u32`s that were greater than others
came after those others.
Wrapping makes this assumption false.
When `EntityGeneration` was created, it retained the `u32` ordering,
which was useless at best and wrong at worst.
This pr fixes the ordering implementation, so new generations are
greater than older generations.

Some users were already accounting for this ordering issue (which was
still present in 0.16 and before) by manually accessing the `u32`
representation. This made migrating difficult for avian physics; see
[here](https://discord.com/channels/691052431525675048/749335865876021248/1377431569228103780).

I am generally of the opinion that this type should be kept opaque to
prevent accidental misuse.
As we find issues like this, the functionality should be added to
`EntityGeneration` directly.

## Solution

Fix the ordering implementation through `Ord`.

Alternatively, we could keep `Ord` the same and make a `cmp_age` method,
but I think this is better, even though sorting entity ids may be
*marginally* slower now (but more correct). This is a tradeoff.

## Testing

I improved documentation for aliasing and ordering, adding some doc
tests.
2025-05-29 05:48:32 +00:00
..
entity EntityGeneration ordering (#19421) 2025-05-29 05:48:32 +00:00
error More uninlined_format_args fixes (#19396) 2025-05-28 02:35:18 +00:00
event Remove apostrophes in possessive its (#19244) 2025-05-26 19:53:14 +00:00
observer Remove ArchetypeComponentId and archetype_component_access (#19143) 2025-05-27 19:04:32 +00:00
query Remove ArchetypeComponentId and archetype_component_access (#19143) 2025-05-27 19:04:32 +00:00
reflect Make remove_reflect parameter names consistent between ReflectCommandExt and impl for EntityCommands (#19243) 2025-05-26 19:49:56 +00:00
relationship Fix custom relations panics with parent/child relations (#19341) 2025-05-27 21:05:31 +00:00
schedule More uninlined_format_args fixes (#19396) 2025-05-28 02:35:18 +00:00
storage Remove ArchetypeComponentId and archetype_component_access (#19143) 2025-05-27 19:04:32 +00:00
system Remove ArchetypeComponentId and archetype_component_access (#19143) 2025-05-27 19:04:32 +00:00
world More uninlined_format_args fixes (#19396) 2025-05-28 02:35:18 +00:00
archetype.rs Remove ArchetypeComponentId and archetype_component_access (#19143) 2025-05-27 19:04:32 +00:00
batching.rs Nonmax all rows (#19132) 2025-05-26 17:39:55 +00:00
bundle.rs Fix EntityMeta.spawned_or_despawned unsoundness (#19350) 2025-05-27 22:45:07 +00:00
change_detection.rs Fix EntityMeta.spawned_or_despawned unsoundness (#19350) 2025-05-27 22:45:07 +00:00
component.rs refactor(utils): move SyncCell and SyncUnsafeCell to bevy_platform (#19305) 2025-05-27 04:57:26 +00:00
entity_disabling.rs
hierarchy.rs More uninlined_format_args fixes (#19396) 2025-05-28 02:35:18 +00:00
intern.rs Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
label.rs Remove upcasting methods + Cleanup interned label code (#18984) 2025-05-26 15:38:12 +00:00
lib.rs Remove ArchetypeComponentId and archetype_component_access (#19143) 2025-05-27 19:04:32 +00:00
name.rs Make entity generation a new type and remove identifier (#19121) 2025-05-08 04:03:05 +00:00
never.rs Use never_say_never hack to work around Rust 2024 regression for fn traits (#18804) 2025-04-14 19:59:48 +00:00
removal_detection.rs
resource.rs refactor(utils): move SyncCell and SyncUnsafeCell to bevy_platform (#19305) 2025-05-27 04:57:26 +00:00
spawn.rs Increase upper limit of children! (#18865) 2025-05-06 00:58:30 +00:00
traversal.rs Add missing words in Traversal doc comment (#19298) 2025-05-19 19:34:59 +00:00