-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Bevy version
0.16
What you did
I noticed this when I tried to check if an entity by index is currently in use.
I ran this test:
let mut world = World::new();
let entity_mut = world.spawn_empty();
let existing = entity_mut.id();
let entity_index = existing.index();
entity_mut.despawn();
let freed = world
.entities()
.resolve_from_id(entity_index)
.expect("freed entities are still allocated");
assert_eq!(
world.entities().contains(freed),
false,
"before: {existing}, freed: {freed}"
)
What went wrong
The test failed:
assertion `left == right` failed: before: 0v1, freed: 0v2
left: true
right: false
stack backtrace:
This is unexpected because resolve_from_id
docs say:
Get the
Entity
with a given id, if it exists in thisEntities
collection ReturnsNone
if thisEntity
is outside of the range of currently reservedEntities
Note: This method may return Entities which are currently free Note that
contains
will correctly return false for freed entities, since it checks the generation
I would think contains
works as a way of verifying if the entity of this index is freed. However this is only done by get
as that method also checks the current archetype.
I am unsure what the issue is here, the docs or the implementation. But I think that contains
should never return true for a freed entity no matter if the generation value has been increased by free
or I took a good guess when using Entity::from_bits
.