Hyperfy ECS
A high performance ECS framework for the web.
See TECHNICAL.md for details on performance and the internals of this library.
Quickstart
static props = type: TypesText static props = value: Object3D static queries = added: Model modified: Mesh removed: Mesh { thisqueriesadded thisqueriesmodified thisqueriesremoved } const world = worldsystemsworldcomponents worldentities { world }
Worlds
Creating a world
const world =
Updating the world
world
Entities
Creating an entity
const basketball = worldentities
Adding components
basketball
Retrieving components
const model = basketball
Marking a component as modified
If you use queries that need to know when components are modified you will need to mark them as modified.
const model = basketballmodelpath = 'basketball-2.glb'model
Removing components
basketball
Activating an entity
Entities are inactive by default and are not simulated in the world until they are activated:
basketball
Deactivating an entity
If you want to remove an entity from the world but still keep it around, use deactivate. When deactivated, all Components are temporarily removed except StateComponents, so that System queries can still process and deallocate any resources.
basketball
Destroying an entity
If you want to completely remove an entity, use destroy. All Components are removed except StateComponents so that System queries can still process and deallocate resources. Once all StateComponents are removed the entity is completely destroyed.
basketball
Components
Defining components
static props = path: TypesText
Registering components
worldcomponents
This method also accepts an array of Components.
StateComponents
StateComponents work the same way as regular Components but are kept around after an entity is deactivated or destroyed so that Systems can process or deallocate resources.
static props = value: TypesObject3D
Systems
Defining systems
static queries = added: Model modified: Mesh removed: Mesh { thisqueriesadded thisqueriesmodified thisqueriesremoved }
Registering systems
worldsystems
This method also accepts an array of Systems