Making the most of ECS identifiers

Created on 2024-03-28T13:09:26-05:00

Return to the Index

This card pertains to a resource available on the internet.

This card can also be read via Gemini.

When using large values like 64-bit integers, you can sneak data in to the upper bits if you are unlikely to need that many unique identifiers.

Storing a generation counter in the upper bits allows you to use generational memory to check for leaks and liveness. Each entity record has a generation that increments per-allocation, so handles can tell if they are likely pointing at an outdated thing.

If components and entities share ID space you can more easily treat components as entities.

Entity pairs: upper 32-bit and lower 32-bit are just two entity IDs combined.

Relationships store IDs as entity pairs while regular entity references include the generation count.

Allowing general entity-entity attachments opens up tricks like using entities to group units in to platoons in an RTS.

For entity relationships the pair is (PredicateEntity, RelatedEntity.)