- ComponentRef
- ComponentData
- registerComponent
- registerComponents
- hasComponent
- getComponent
- set
- recursivelyInherit
- ComponentSetter
- setComponent
- addComponent
- addComponents
- removeComponent
- removeComponents
- addPrefab
- addEntity
- removeEntity
- getEntityComponents
- entityExists
- EntityIndex
- getId
- getVersion
- incrementVersion
- withVersioning
- createEntityIndex
- addEntityId
- removeEntityId
- isEntityIdAlive
- growDepthsArray
- updateDepthCache
- updateMaxDepth
- setEntityDepth
- invalidateQueryCache
- getHierarchyData
- populateExistingDepths
- ensureDepthTracking
- calculateEntityDepth
- getEntityDepthWithVisited
- getEntityDepth
- markChildrenDirty
- updateHierarchyDepth
- invalidateHierarchyDepth
- invalidateSubtree
- flushDirtyDepths
- queryHierarchy
- queryHierarchyDepth
- getHierarchyDepth
- getMaxHierarchyDepth
- QueryResult
- QueryOptions
- Query
- QueryOperatorType
- $opType
- $opTerms
- OpReturnType
- QueryOperator
- QueryTerm
- HierarchyTerm
- Hierarchy
- Cascade
- QueryModifier
- ObservableHook
- observe
- queryHash
- registerQuery
- queryInternal
- query
- queryCheckEntity
- queryCheckComponent
- queryAddEntity
- queryCommitRemovals
- commitRemovals
- queryRemoveEntity
- removeQuery
- OnTargetRemovedCallback
- RelationTarget
- $relation
- $pairTarget
- $isPairComponent
- $relationData
- RelationData
- Relation
- createBaseRelation
- withStore
- makeExclusive
- withAutoRemoveSubject
- withOnTargetRemoved
- withValidation
- Pair
- getRelationTargets
- createRelation
- createRelation
- $wildcard
- createWildcardRelation
- getWildcard
- Wildcard
- createIsARelation
- getIsA
- IsA
- isWildcard
- isRelation
- createWorld
- resetWorld
- deleteWorld
- getWorldComponents
- getAllEntities
Represents a reference to a component.
Type: any
Represents the data associated with a component.
idnumber The unique identifier for the component.generationIdnumber The generation ID of the component.bitflagnumber The bitflag used for component masking.refComponentRef Reference to the component.queriesSet<Query> Set of queries associated with the component.setObservableObservable Observable for component changes.
Registers a component with the world.
worldWorld The world object.componentComponentRef The component to register.
- Throws Error If the component is null or undefined.
Returns ComponentData The registered component data.
Registers multiple components with the world.
worldWorld The world object.componentsArray<ComponentRef> Array of components to register.
Checks if an entity has a specific component.
worldWorld The world object.eidnumber The entity ID.componentComponentRef The component to check for.
Returns boolean True if the entity has the component, false otherwise.
Retrieves the data associated with a component for a specific entity.
worldWorld The world object.eidEntityId The entity ID.componentComponentRef The component to retrieve data for.
Returns any The component data, or undefined if the component is not found or the entity doesn't have the component.
Helper function to set component data.
componentComponentRef The component to set.dataany The data to set for the component.
Returns {component: ComponentRef, data: any} An object containing the component and its data.
Recursvely inherits components from one entity to another.
ctxWorldContextworldWorld The world object.baseEidnumber The ID of the entity inheriting components.inheritedEidnumber The ID of the entity being inherited from.visited(optional, defaultnew Set<EntityId>())isFirstSuperboolean Whether this is the first super in the inheritance chain.
Returns void
Represents a component with data to be set on an entity.
Type: {component: ComponentRef, data: T}
componentComponentRefdataT
Sets component data on an entity. Always calls the setter observable even if entity already has the component.
worldWorld The world object.eidEntityId The entity ID.componentComponentRef The component to set.dataany The data to set for the component.
- Throws Error If the entity does not exist in the world.
Returns void
Adds a single component to an entity.
worldWorld The world object.eidEntityId The entity ID.componentOrSet(ComponentRef | ComponentSetter) Component to add or set.
- Throws Error If the entity does not exist in the world.
Returns boolean True if component was added, false if it already existed.
Adds multiple components to an entity.
worldWorld The world object.eidEntityId The entity ID.components(Array<(ComponentRef | ComponentSetter)> | ComponentRef | ComponentSetter) Components to add or set (array or spread args).
- Throws Error If the entity does not exist in the world.
Returns void
Removes one or more components from an entity.
worldWorld The world object.eidnumber The entity ID.components...ComponentRef Components to remove.
- Throws Error If the entity does not exist in the world.
Removes one or more components from an entity. This is an alias for removeComponent.
worldWorld The world object.eidEntityId The entity ID.components...ComponentRef Components to remove.
- Throws Error If the entity does not exist in the world.
Creates a new prefab entity in the world. Prefabs are special entities marked with the Prefab component that are excluded from normal queries and can be used as templates for creating other entities.
worldWorld The world object to create the prefab in.
Returns EntityId The entity ID of the created prefab.
Adds a new entity to the specified world.
worldWorld
Returns number eid
Removes an existing entity from the specified world.
worldWorldeidnumber
Returns an array of components that an entity possesses.
worldanyeidany
Returns Array<ComponentRef>
Checks the existence of an entity in a world
worldWorldeidnumber
Represents the structure for managing entity IDs.
Type: {aliveCount: number, dense: Array<number>, sparse: Array<number>, maxId: number, versioning: boolean, versionBits: number, entityMask: number, versionShift: number, versionMask: number}
aliveCountnumberdenseArray<number>sparseArray<number>maxIdnumberversioningbooleanversionBitsnumberentityMasknumberversionShiftnumberversionMasknumber
The number of currently alive entities.
Type: number
Array of entity IDs, densely packed.
Sparse array mapping entity IDs to their index in the dense array.
The highest entity ID that has been assigned.
Type: number
Flag indicating if versioning is enabled.
Type: boolean
Number of bits used for versioning.
Type: number
Bit mask for entity ID.
Type: number
Bit shift for version.
Type: number
Bit mask for version.
Type: number
Extracts the entity ID from a versioned entity ID by stripping off the version.
indexEntityIndex The EntityIndex containing the masks.idnumber The versioned entity ID.
Returns number The entity ID without the version.
Extracts the version from an entity ID.
indexEntityIndex The EntityIndex containing the masks and shifts.idnumber The entity ID.
Returns number The version.
Increments the version of an entity ID.
indexEntityIndex The EntityIndex containing the masks and shifts.idnumber The entity ID.
Returns number The new entity ID with incremented version.
Creates configuration options for entity ID recycling with versioning.
versionBitsnumber? Optional number of bits to use for version numbers. Defaults to 8 if not specified.
Returns object Configuration object with versioning enabled and specified version bits.
Creates and initializes a new EntityIndex.
-
options(object | function)? Optional configuration object from withVersioning() or withVersioning function.
Returns EntityIndex A new EntityIndex object.
Adds a new entity ID to the index or recycles an existing one.
indexEntityIndex The EntityIndex to add to.
Returns number The new or recycled entity ID.
Removes an entity ID from the index.
indexEntityIndex The EntityIndex to remove from.idnumber The entity ID to remove.
Returns void
Checks if an entity ID is currently alive in the index.
indexEntityIndex The EntityIndex to check.idnumber The entity ID to check.
Returns boolean True if the entity ID is alive, false otherwise.
Grows the depths array to accommodate a specific entity
hierarchyDataHierarchyDataentityEntityId
Returns Uint32Array
Updates the depthToEntities cache when an entity's depth changes
Returns void
Updates max depth if the new depth is greater
hierarchyDataHierarchyDatadepthnumber
Returns void
Sets entity depth and updates all related caches
Returns void
Invalidates hierarchy query cache for a relation
worldWorldrelationComponentRef
Returns void
Gets hierarchy data for a relation, activating tracking if needed
worldWorldrelationComponentRef
Returns HierarchyData
Populates depth calculations for all existing entities with this relation
worldWorldrelationComponentRef
Returns void
Ensures depth tracking is initialized for a relation. This must be called before using hierarchy features for a specific relation component.
worldWorld The world object.relationComponentRef The relation component to initialize tracking for.
Returns void
Calculates the hierarchy depth of an entity for a given relation. Depth is measured as the distance from the root entities (entities with no parent relations).
worldWorld The world object.relationComponentRef The relation component to calculate depth for.entityEntityId The entity ID to calculate depth for.visitedSet<EntityId>? Internal set to track visited entities for cycle detection. (optional, defaultnew Set<EntityId>())
Returns number The hierarchy depth of the entity.
Internal helper to get entity depth with cycle detection
worldWorldrelationComponentRefentityEntityIdvisitedSet<EntityId>
Returns number
Gets the cached depth of an entity, calculating if needed
worldWorldrelationComponentRefentityEntityId
Returns number
Marks an entity and its children as needing depth recalculation. This is used internally when hierarchy changes occur.
worldWorld The world object.relationComponentRef The relation component.parentEntityId The parent entity ID.dirtySparseSet The set to mark dirty entities in.visitedSparseSet? Internal set to track visited entities for cycle detection. (optional, defaultcreateSparseSet())
Returns void
Updates hierarchy depth when a relation is added. This function is called automatically when components are added to maintain accurate depth tracking.
worldWorld The world object.relationComponentRef The relation component.entityEntityId The entity ID that had a relation added.parentEntityId? The parent entity ID in the relation.updatingSet<EntityId>? Internal set to track entities being updated. (optional, defaultnew Set<EntityId>())
Returns void
Invalidates hierarchy depth when a relation is removed. This function is called automatically when components are removed to maintain accurate depth tracking.
worldWorld The world object.relationComponentRef The relation component.entityEntityId The entity ID that had a relation removed.
Returns void
Recursively invalidates an entire subtree
worldWorldrelationComponentRefentityEntityIddepthsUint32ArrayvisitedSparseSet
Returns void
Processes all dirty depth calculations for a relation. This ensures all cached depth values are up to date before performing hierarchy operations.
worldWorld The world object.relationComponentRef The relation component to flush dirty depths for.
Returns void
Query entities in hierarchical order (depth-based ordering). Returns entities grouped by depth: all depth 0, then depth 1, then depth 2, etc. This ensures parents always come before their children.
-
worldWorld The world object. -
relationComponentRef The relation component that defines the hierarchy. -
componentsArray<ComponentRef> Additional components to filter by. -
optionsObject? Query options. (optional, default{})options.bufferedboolean? Whether to return results as Uint32Array instead of number[].
Returns QueryResult Array or Uint32Array of entity IDs in hierarchical order.
Get all entities at a specific depth level in the hierarchy.
-
worldWorld The world object. -
relationComponentRef The relation component that defines the hierarchy. -
depthnumber The specific depth level to query (0 = root level). -
optionsObject? Query options. (optional, default{})options.bufferedboolean? Whether to return results as Uint32Array instead of number[].
Returns QueryResult Array or Uint32Array of entity IDs at the specified depth.
Get the hierarchy depth of a specific entity for a given relation.
worldWorld The world object.entityEntityId The entity ID to get depth for.relationComponentRef The relation component that defines the hierarchy.
Returns number The depth of the entity (0 = root level, higher numbers = deeper).
Get the maximum depth in the hierarchy for a given relation.
worldWorld The world object.relationComponentRef The relation component that defines the hierarchy.
Returns number The maximum depth found in the hierarchy.
The result of a query, either as a Uint32Array or a readonly array of numbers.
Type: (Uint32Array | any)
Options for configuring query behavior.
Type: Object
commitboolean? Whether to commit pending entity removals before querying.bufferedboolean? Whether to return results as Uint32Array instead of number[].
Represents a query in the ECS using original blazing-fast bitmask evaluation.
Type: Object
allComponentsArray<ComponentRef> All components referenced in the query.orComponentsArray<ComponentRef> Components in an OR relationship.notComponentsArray<ComponentRef> Components that should not be present.masksRecord<number, number> Bitmasks for each component generation.orMasksRecord<number, number> OR bitmasks for each component generation.notMasksRecord<number, number> NOT bitmasks for each component generation.hasMasksRecord<number, number> HAS bitmasks for each component generation.generationsArray<number> Component generations.toRemoveSparseSet Set of entities to be removed.
Types of query operators.
Type: ("Or" | "And" | "Not")
Symbol for query operator type.
Type: Symbol
Symbol for query operator terms.
Type: Symbol
Type: Object
$opTypesymbol? The type of the operator.$opTermssymbol? The components involved in the operation.
A function that creates a query operator.
Type: Function
components...ComponentRef The components to apply the operator to.
Returns OpReturnType The result of the operator.
A term in a query, either a component reference, query operator, or hierarchy term.
Type: (ComponentRef | QueryOperator | HierarchyTerm)
Represents a hierarchy query term for topological ordering.
Type: Object
$hierarchyTypesymbol? Always 'Hierarchy'.$hierarchyRelComponentRef? The relation component for hierarchy.$hierarchyDepthnumber? Optional depth limit.
Creates a hierarchy query term for topological ordering (parents before children).
relationComponentRef The relation component (e.g., ChildOf).depthnumber? Optional depth limit.
Returns HierarchyTerm The hierarchy term.
Alias for Hierarchy - creates a hierarchy query term for topological ordering.
relationComponentRef The relation component (e.g., ChildOf).depthnumber? Optional depth limit.
Returns HierarchyTerm The hierarchy term.
Represents a query modifier that can be mixed into query terms.
Type: Object
$modifierTypesymbol? The type of modifier ('buffer' | 'nested').
A function that creates an observable hook for queries.
Type: Function
terms...QueryTerm The query terms to observe.
Observes changes in entities based on specified components.
worldWorld The world object.hookObservableHook The observable hook.callbackfunction (number): any The callback function to execute when changes occur.
Returns function (): void A function to unsubscribe from the observation.
Generates a hash for a query based on its terms.
Returns string The generated hash.
Registers a new query in the world using unified clause-mask compilation.
-
worldWorld The world object. -
optionsObject? Additional options.options.bufferedboolean? Whether the query should be buffered.
Returns Query The registered query.
Internal implementation for nested queries.
-
worldWorld The world object. -
optionsObject? Additional options.options.bufferedboolean? Whether the query should be buffered.
Returns QueryResult The result of the query.
Performs a unified query operation with configurable options.
worldWorld The world object.termsArray<QueryTerm> The query terms.modifiers...QueryModifier Query modifiers (asBuffer, isNested, etc.).
Returns QueryResult The result of the query.
Original blazing-fast query evaluation using simple bitmasks.
worldWorld The world object.queryQuery The query to check against.eidnumber The entity ID to check.
Returns boolean True if the entity matches the query, false otherwise.
Checks if a component matches a query.
queryQuery The query to check against.cComponentData The component data to check.
Returns boolean True if the component matches the query, false otherwise.
Adds an entity to a query.
Commits removals for a query.
queryQuery The query to commit removals for.
Commits all pending removals for queries in the world.
worldWorld The world object.
Removes an entity from a query.
worldWorld The world object.queryQuery The query to remove the entity from.eidnumber The entity ID to remove.
Removes a query from the world.
Callback function type for when a target is removed from a relation.
Type: Function
Possible types for a relation target.
Type: (number | "*" | any)
Symbol for accessing the relation of a component.
Type: Symbol
Symbol for accessing the pair target of a component.
Type: Symbol
Symbol for checking if a component is a pair component.
Type: Symbol
Symbol for accessing the relation data of a component.
Type: Symbol
Interface for relation data.
Type definition for a Relation function.
Type: function
targetRelationTarget The target of the relation.
Returns T The relation component.
Creates a base relation.
Returns Relation<T> The created base relation.
Adds a store to a relation.
createStorefunction (): T Function to create the store.
Returns function (Relation<T>): Relation<T> A function that modifies the relation.
Makes a relation exclusive.
relationRelation<T> The relation to make exclusive.
Returns Relation<T> The modified relation.
Adds auto-remove subject behavior to a relation.
relationRelation<T> The relation to modify.
Returns Relation<T> The modified relation.
Adds an onTargetRemoved callback to a relation.
onRemoveOnTargetRemovedCallback The callback to add.
Returns function (Relation<T>): Relation<T> A function that modifies the relation.
Adds validation to a relation.
validateFnfunction (T): boolean The validation function.
Returns function (Relation<T>): Relation<T> A function that modifies the relation.
Creates a pair from a relation and a target.
relationRelation<T> The relation.targetRelationTarget The target.
- Throws Error If the relation is undefined.
Returns T The created pair.
Gets the relation targets for an entity.
worldWorld The world object.eidnumber The entity ID.relationRelation<any> The relation to get targets for.
Returns Array<any> An array of relation targets.
Creates a new relation.
Returns Relation<T> The created relation.
Creates a new relation with options.
-
optionsObject Options for creating the relation.options.storefunction (): T? Function to create the store.options.exclusiveboolean? Whether the relation is exclusive.options.autoRemoveSubjectboolean? Whether to auto-remove the subject.options.onTargetRemovedOnTargetRemovedCallback? Callback for when a target is removed.
Returns Relation<T> The created relation.
Symbol used to mark a relation as a wildcard relation
Creates a wildcard relation that matches any target.
Returns Relation<T> The created wildcard relation.
Gets the singleton wildcard instance.
Returns Relation<any> The global wildcard relation instance.
Wildcard relation.
Type: Relation<any>
Creates an IsA relation.
Returns Relation<T> The created IsA relation.
Gets the singleton IsA instance.
Returns Relation<any> The global IsA relation instance.
IsA relation.
Type: Relation<any>
Checks if a relation is a wildcard relation.
relationany The relation to check.
Returns boolean True if the relation is a wildcard relation, false otherwise.
Checks if a component is a relation.
componentany The component to check.
Returns boolean True if the component is a relation, false otherwise.
Creates a new world with various configurations.
args...Array<(EntityIndex | object)> EntityIndex, context object, or both.
Returns World<T> The created world.
Resets a world.
worldWorld
Returns object
Deletes a world by removing its internal data.
worldWorld The world to be deleted.
Returns all components registered to a world
worldWorld
Returns any Array
Returns all existing entities in a world
worldWorld
Returns any Array