Skip to main content

Entity

API for creating and manipulating entities as well as components.

Constants

Entity.Components.Name

The name component.

Entity.Components.Name: component

Entity.Components.Position

The position component.

Entity.Components.Position: component

Entity.Components.Rotation

The rotation component.

Entity.Components.Rotation: component

Entity.Components.Scale

The scale component.

Entity.Components.Scale: component

Functions

Entity.create

Creates a new entity.

Entity.create(): entity

Returns

NameTypeDescription
entityentityThe newly created entity.

Entity.fromAsset3d

Creates a new entity from an Asset3d.

Entity.fromAsset3d(assetPath: string, position: vector, rotation: Quaternion): entity

Parameters

NameTypeDefault ValueDescription
assetPathstringRequiredThe path of the Asset3d to create the entity from.
positionvectorRequiredThe position of the entity.
rotationQuaternionRequiredThe rotation of the entity.

Returns

NameTypeDescription
entityentityThe newly created entity.

Entity.destroy

Destroys an entity.

Entity.destroy(entity: entity)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to destroy.

Entity.createComponent

Creates a new component.

Performance for Component Types

Primitive component types are the fastest to create and access. Primitive component types include:

  • boolean
  • integer
  • unsigned
  • number
  • string
  • vector
  • quaternion

Reference component types are slower to create and access. Reference component types include:

  • table
  • buffer
  • function
  • userdata
  • thread
Entity.createComponent(type: 'boolean' | 'integer' | 'unsigned' | 'number' | 'string' | 'vector' | 'quaternion' | 'table' | 'buffer' | 'function' | 'userdata' | 'thread'): component

Parameters

NameTypeDefault ValueDescription
type'boolean' | 'integer' | 'unsigned' | 'number' | 'string' | 'vector' | 'quaternion' | 'table' | 'buffer' | 'function' | 'userdata' | 'thread'RequiredThe type of component to create.

Returns

NameTypeDescription
componentcomponentThe newly created component.

Entity.isValid

Checks if an entity is valid.

Entity.isValid(entity: entity): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to check.

Returns

NameTypeDescription
validbooleanWhether the entity is valid.

Entity.getId

Gets the ID of an entity.

Entity.getId(entity: entity): number

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the ID of.

Returns

NameTypeDescription
idnumberThe ID of the entity.

Entity.findByComponents

Finds entities which contain the given components.

Entity.findByComponents(components: component[]): entity[]

Parameters

NameTypeDefault ValueDescription
componentscomponent[]RequiredThe components to search for.

Returns

NameTypeDescription
entitiesentity[]The entities which contain the given components.

Entity.getComponent

Gets a component from an entity.

Entity.getComponent(entity: entity, component: component): any

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the component from.
componentcomponentRequiredThe component to get.

Returns

NameTypeDescription
dataanyThe component data from the entity.

Entity.setComponent

Sets component data on an entity.

Entity.setComponent(entity: entity, component: component, data: any)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to set the component on.
componentcomponentRequiredThe component to set.
dataanyRequiredThe data to set.

Entity.removeComponent

Removes a component from an entity.

Entity.removeComponent(entity: entity, component: component)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to remove the component from.
componentcomponentRequiredThe component to remove.

Entity.hasComponent

Checks if an entity has a component.

Entity.hasComponent(entity: entity, component: component): boolean

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to check.
componentcomponentRequiredThe component to check for.

Returns

NameTypeDescription
hasComponentbooleanWhether the entity has the component.

Entity.getParent

Gets the parent of an entity.

Entity.getParent(entity: entity): entity?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the parent of.

Returns

NameTypeDescription
parententity?The parent of the entity.

Entity.getChildren

Gets the children of an entity.

Entity.getChildren(entity: entity): entity[]

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the children of.

Returns

NameTypeDescription
childrenentity[]The children of the entity.

Entity.getGlobalPosition

Gets the global position of an entity.

Entity.getGlobalPosition(entity: entity): vector?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the global position of.

Returns

NameTypeDescription
positionvector?The global position of the entity.

Entity.getGlobalRotation

Gets the global rotation of an entity.

Entity.getGlobalRotation(entity: entity): Quaternion?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the global rotation of.

Returns

NameTypeDescription
rotationQuaternion?The global rotation of the entity.

Entity.getGlobalScale

Gets the global scale of an entity.

Entity.getGlobalScale(entity: entity): vector?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the global scale of.

Returns

NameTypeDescription
scalevector?The global scale of the entity.

Entity.getName

Gets the name of an entity.

Entity.getName(entity: entity): string?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the name of.

Returns

NameTypeDescription
namestring?The name of the entity.

Entity.setName

Sets the name of an entity.

Entity.setName(entity: entity, name: string)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to set the name of.
namestringRequiredThe name to set.

Entity.getLocalPosition

Gets the local position of an entity.

Entity.getLocalPosition(entity: entity): vector?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the local position of.

Returns

NameTypeDescription
positionvector?The local position of the entity.

Entity.getLocalRotation

Gets the local rotation of an entity.

Entity.getLocalRotation(entity: entity): Quaternion?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the local rotation of.

Returns

NameTypeDescription
rotationQuaternion?The local rotation of the entity.

Entity.getLocalScale

Gets the local scale of an entity.

Entity.getLocalScale(entity: entity): vector?

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to get the local scale of.

Returns

NameTypeDescription
scalevector?The local scale of the entity.

Entity.setLocalPosition

Sets the local position of an entity.

Entity.setLocalPosition(entity: entity, position: vector)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to set the local position of.
positionvectorRequiredThe local position to set.

Entity.setLocalRotation

Sets the local rotation of an entity.

Entity.setLocalRotation(entity: entity, rotation: Quaternion)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to set the local rotation of.
rotationQuaternionRequiredThe local rotation to set.

Entity.setLocalScale

Sets the local scale of an entity.

Entity.setLocalScale(entity: entity, scale: vector)

Parameters

NameTypeDefault ValueDescription
entityentityRequiredThe entity to set the local scale of.
scalevectorRequiredThe local scale to set.