This service is responsible for assigning and tracking unique numerical identifiers for Entities. It maintains the relationship between an Entity and its UID in both directions, allowing Entities to be resolved from serialized identifiers and existing Entities to retrieve their assigned UID.
Entity UIDs are heavily used during serialization and deserialization to preserve references to specific Entities across saved state. New UIDs are generated from the current game's maxUID value, ensuring that newly assigned identifiers remain unique within the game state.
| Method | uint GetEntityUID(IEntity? entity = null) |
|---|---|
| Description | Returns the UID associated with specified IEntity if it is already registered. If the Entity has no registered UID, a new UID is generated by incrementing the current game's maxUID value and the Entity is registered against it. If no Entity is supplied, a new UID is generated and returned without registering it to an Entity. |
| Method | bool TryGetRegisteredEntity(uint uid, out IEntity? entity) |
|---|---|
| Description | Attempts to retrieve the IEntity registered to specified UID. Returns true and outputs the Entity if a registration exists. Returns false and outputs null if the UID is not currently associated with an Entity. |
| Method | void RegisterUIDForEntity(IEntity entity, uint uid) |
|---|---|
| Description | Manually associates specified IEntity with specified UID. If the UID is already registered to the same Entity, nothing happens. If the UID is already registered to a different Entity, an InvalidOperationException is thrown. This is primarily useful when restoring Entity identifiers from serialized data where an existing UID must be preserved. |
| Method | void ReleaseUID(uint uid) |
|---|---|
| Description | Releases specified UID and removes its association with the registered IEntity. Nothing happens if the UID is not currently registered. |
| Method | void Reset() |
|---|---|
| Description | Clears all currently registered Entity-to-UID and UID-to-Entity associations. This does not modify the current game's maxUID value. |