EntityReference
EntityReference
Uniquely identifies an entity by both its ID and generation. Lets us uniquely distinguish between two entities, even those with the same ID that were created at different times
Kind: global class
See: EntityComponentDataset
Author: Alex Goldring
Copyright: Company Named Limited (c) 2025
- EntityReference
- new exports.EntityReference()
- instance
- .id :
number - .generation :
number - .isEntityReference :
boolean - .copy(other)
- .clone() ⇒
EntityReference - .hash() ⇒
number - .equals(other) ⇒
boolean - .verify(ecd) ⇒
boolean - .destroy(ecd) ⇒
boolean - .bind(ecd, entity)
- .from(id, generation)
- .id :
- static
new exports.EntityReference()
Example
// 1. Get your EntityComponentDataset to where you manager entities.
const ecd = ... ; // EntityComponentDataset
// 2. Create an entity (we'll get an ID).
const entityId = ecd.createEntity();
// 3. Create an EntityReference and bind it to the entity.
const entityRef = EntityReference.bind(ecd, entityId);
// 4. After you no longer need the entity - destroy the entity via reference.
entityRef.destroy(ecd);
entityReference.id : number
Entity ID
When entity is live - this is the entity ID inside associated EntityComponentDataset, when the entity is not live - it's set to -1
Kind: instance property of EntityReference
entityReference.generation : number
Entity generation number. This uniquely identifies an entity in combination with the ID Generation of an existing entity must match for it to be considered "the same".
Kind: instance property of EntityReference
See: EntityComponentDataset.getEntityGeneration
entityReference.isEntityReference : boolean
Kind: instance property of EntityReference
Read only: true
entityReference.copy(other)
Kind: instance method of EntityReference
| Param | Type |
|---|---|
| other | EntityReference |
entityReference.clone() ⇒ EntityReference
Kind: instance method of EntityReference
entityReference.hash() ⇒ number
Kind: instance method of EntityReference
entityReference.equals(other) ⇒ boolean
Kind: instance method of EntityReference
| Param | Type |
|---|---|
| other | EntityReference |
entityReference.verify(ecd) ⇒ boolean
Checks whether referenced entity exists and the generation matches
Kind: instance method of EntityReference
| Param | Type |
|---|---|
| ecd | EntityComponentDataset |
entityReference.destroy(ecd) ⇒ boolean
Destroys entity bound to this reference If the reference is invalid for the given dataset - does nothing
Kind: instance method of EntityReference
Returns: boolean - true if entity was destroyed, false otherwise
| Param | Type |
|---|---|
| ecd | EntityComponentDataset |
entityReference.bind(ecd, entity)
Bind reference to a specific entity
Kind: instance method of EntityReference
| Param | Type |
|---|---|
| ecd | EntityComponentDataset |
| entity | number |
entityReference.from(id, generation)
Kind: instance method of EntityReference
| Param | Type |
|---|---|
| id | number |
| generation | number |
EntityReference.NULL : EntityReference
Special utility singleton to describe an invalid reference.
Kind: static property of EntityReference
Read only: true
EntityReference.from(id, generation) ⇒ EntityReference
Kind: static method of EntityReference
| Param | Type |
|---|---|
| id | number |
| generation | number |
EntityReference.bind(ecd, id) ⇒ EntityReference
Kind: static method of EntityReference
| Param | Type |
|---|---|
| ecd | EntityComponentDataset |
| id | number |