Skip to main content

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

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

ParamType
otherEntityReference

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

ParamType
otherEntityReference

entityReference.verify(ecd) ⇒ boolean

Checks whether referenced entity exists and the generation matches

Kind: instance method of EntityReference

ParamType
ecdEntityComponentDataset

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

ParamType
ecdEntityComponentDataset

entityReference.bind(ecd, entity)

Bind reference to a specific entity

Kind: instance method of EntityReference

ParamType
ecdEntityComponentDataset
entitynumber

entityReference.from(id, generation)

Kind: instance method of EntityReference

ParamType
idnumber
generationnumber

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

ParamType
idnumber
generationnumber

EntityReference.bind(ecd, id) ⇒ EntityReference

Kind: static method of EntityReference

ParamType
ecdEntityComponentDataset
idnumber