When are entity identifiers reused? #1205
-
See title. I'm trying to evaluate how dangerous it is to have a component that references an entity with a different lifetime. I'd like to know when calling registry::valid on a destroyed entity will no longer return false. A simple test reveals that entities aren't reused immediately, but I don't know how reliable this behavior is: auto registry = entt::registry();
auto foo = registry.create();
registry_.destroy(foo);
for (int i = 0; i < 1'000'000; i++) {
registry.create(); // Create a lot of entities.
}
assert(!registry.valid(foo)); // Okay, foo is still invalid. In this discussion a similar problem is acknowledged, but it's still not clear to me what pattern will result in the reuse of an entity+version, nor if there's supposed to be a guarantee. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Identifiers have an entity part and a version part. The version is incremented when you destroy it. The entity remains stable instead. |
Beta Was this translation helpful? Give feedback.
Identifiers have an entity part and a version part. The version is incremented when you destroy it. The entity remains stable instead.
This means that the identifiers appears again in your game when the version wraps to 0 again. The default version for a 32b identifier is 12b. As anything else in EnTT, the version part as well as the type used for identifiers can be customized if you like.