API for creating and manipulating entities as well as components.
Functions Entity.create Creates a new entity.
Entity.create (shouldReplicate?: boolean): entity Parameters Name Type Default Value Description shouldReplicate boolean?falseTrue if the entity should replicate to clients.
Returns Name Type Description entity entityThe newly created entity.
Entity.create Creates a new entity.
Returns Name Type Description entity entityThe newly created entity.
Entity.fromAsset3d Creates a new entity hierarchy from an Asset3d.
Entity.fromAsset3d (asset: Asset3d, position: vector, orientation: Quaternion , enablePhysics?: boolean): entity Parameters Name Type Default Value Description asset Asset3dRequired An instance of the asset to create from. position vectorRequired The position of the root entity. orientation QuaternionRequired The orientation of the root entity. enablePhysics boolean?trueWhether to create colliders and constraints from the asset.
Returns Name Type Description entity entityThe root entity of the new hierarchy.
Entity.fromMap Creates entities from a Map.
Entity.fromMap (map: Map): entity[] Parameters Name Type Description map MapAn instance of the map to create from.
Returns Name Type Description entities entity[]List of the entities created
Entity.destroy Destroys an entity.
Entity.destroy (entity: entity) Parameters Name Type Description entity entityThe entity to destroy.
Entity.isValid Checks if an entity is valid.
Entity.isValid (entity: entity): boolean Parameters Name Type Description entity entityThe entity to check.
Returns Name Type Description valid booleanWhether the entity is valid.
Entity.getId Gets the ID of an entity.
Entity.getId (entity: entity): number Parameters Name Type Description entity entityThe entity to get the ID of.
Returns Name Type Description id numberThe ID of the entity.
Entity.isReplicated True if the entity is replicated from the server to clients.
Modifications made to replicated entities on the client will be considered predictions,
and will be overridden when the next update for the entity is sent by the server.
Entity.isReplicated (entity: entity): boolean Parameters Name Type Description entity entityThe entity to check.
Returns Name Type Description replica booleanWhether the entity is replicated.
Entity.createComponent Creates a new component.
Primitive component types are the fastest to create and access .
Primitive component types include:
booleanintegerunsignednumberstringvectorquaternionReference component types are slower to create and access .
Reference component types include:
tablebufferfunctionuserdatathreadEntity.createComponent ( type : 'boolean' | 'integer' | 'unsigned' | 'number' | 'string' | 'vector' | 'quaternion' | 'table' | 'buffer' | 'function' | 'userdata' | 'thread' ): component Parameters Name Type Description type 'boolean' | 'integer' | 'unsigned' | 'number' | 'string' | 'vector' | 'quaternion' | 'table' | 'buffer' | 'function' | 'userdata' | 'thread'The type of component to create.
Returns Name Type Description component componentThe newly created component.
Entity.findByComponents Finds entities which contain the given components.
Entity.findByComponents (components: component[]): entity[] Parameters Name Type Description components component[]The components to search for.
Returns Name Type Description entities entity[]The entities which contain the given components.
Entity.getComponent Gets a component from an entity.
Entity.getComponent (entity: entity, component: component): any Parameters Name Type Description entity entityThe entity to get the component from. component componentThe component to get.
Returns Name Type Description data anyThe component data from the entity.
Entity.setComponent Sets component data on an entity.
Entity.setComponent (entity: entity, component: component, data: any) Parameters Name Type Description entity entityThe entity to set the component on. component componentThe component to set. data anyThe data to set.
Entity.removeComponent Removes a component from an entity.
Entity.removeComponent (entity: entity, component: component) Parameters Name Type Description entity entityThe entity to remove the component from. component componentThe component to remove.
Entity.hasComponent Checks if an entity has a component.
Entity.hasComponent (entity: entity, component: component): boolean Parameters Name Type Description entity entityThe entity to check. component componentThe component to check for.
Returns Name Type Description hasComponent booleanWhether the entity has the component.
Entity.getParent Gets the parent of an entity.
Entity.getParent (entity: entity): entity? Parameters Name Type Description entity entityThe entity to get the parent of.
Returns Name Type Description parent entity?The parent of the entity.
Entity.getChildren Gets the children of an entity.
Entity.getChildren (entity: entity): entity[] Parameters Name Type Description entity entityThe entity to get the children of.
Returns Name Type Description children entity[]The children of the entity.
Entity.setParent Sets the parent of an entity.
Entity.setParent (entity: entity, parent?: entity) Parameters Name Type Description entity entityThe entity to set the parent of. parent entity?The new parent, or nil to remove the entity's parent.
Gets the cached global transform of an entity.
Global transforms are recalculated from entity local transforms once per frame, after Lua executes and before rendering.
This means transforms returned by this method may be out of sync from the local transform of the entity or its ancestors.
You can force an immediate recalculation of an entity's global transform and those of all its ancestors with calculateGlobalTransform,
but beware this isn't cheap if the entity is a deeply nested descendant.
Entity.getCachedGlobalTransform (entity: entity): Transform Parameters Name Type Description entity entityThe entity to get the global transform of.
Returns Name Type Description transform TransformThe cached global transform of the entity.
Immediately recalculates the global transforms of an entity and all of its ancestors.
Global transforms are recalculated from entity local transforms once per frame, after Lua executes and before rendering.
This means transforms returned by getCachedGlobalTransform may be out of sync from the local transform of the entity or its ancestors.
You can force an immediate recalculation of an entity's global transform and those of all its ancestors with this method,
but beware this isn't cheap if the entity is a deeply nested descendant.
You should use getCachedGlobalTransform where possible.
Entity.calculateGlobalTransform (entity: entity): Transform Parameters Name Type Description entity entityThe entity to calculate the global transform of.
Returns Name Type Description transform TransformThe up-to-date global transform of the entity.
Entity.getLocalPosition Gets the local position of an entity.
Entity.getLocalPosition (entity: entity): vector Parameters Name Type Description entity entityThe entity to get the local position of.
Returns Name Type Description position vectorThe local position of the entity.
Entity.getLocalOrientation Gets the local orientation of an entity.
Entity.getLocalOrientation (entity: entity): Quaternion Parameters Name Type Description entity entityThe entity to get the local orientation of.
Returns Name Type Description rotation QuaternionThe local orientation of the entity.
Entity.getLocalScale Gets the local scale of an entity.
Entity.getLocalScale (entity: entity): vector Parameters Name Type Description entity entityThe entity to get the local scale of.
Returns Name Type Description scale vectorThe local scale of the entity.
Entity.setLocalPosition Sets the local position of an entity.
Entity.setLocalPosition (entity: entity, position: vector) Parameters Name Type Description entity entityThe entity to set the local position of. position vectorThe local position to set.
Entity.setLocalOrientation Sets the local orientation of an entity.
Entity.setLocalOrientation (entity: entity, orientation: Quaternion ) Parameters Name Type Description entity entityThe entity to set the local orientation of. orientation QuaternionThe local orientation to set.
Entity.setLocalScale Sets the local scale of an entity.
Entity.setLocalScale (entity: entity, scale: vector) Parameters Name Type Description entity entityThe entity to set the local scale of. scale vectorThe local scale to set.
Entity.getMesh Gets the mesh of an entity.
Entity.getMesh (entity: entity): Mesh? Parameters Name Type Description entity entityThe entity to get the mesh of.
Returns Name Type Description mesh Mesh?Mesh of the entity, or nil if it has none.
Entity.setMesh Sets the mesh of an entity.
Entity.setMesh (entity: entity, mesh?: Mesh) Parameters Name Type Description entity entityThe entity to set the mesh of. mesh Mesh?Mesh to set, or nil to remove the entity's mesh.
Entity.getSkeleton Gets the skeleton of an entity.
Entity.getSkeleton (entity: entity): Skeleton ? Parameters Name Type Description entity entityThe entity to get the skeleton of.
Returns Name Type Description skeleton Skeleton?Skeleton of the entity, or nil if it has none.
Entity.setSkeleton Sets the skeleton of an entity.
Entity.setSkeleton (entity: entity, skeleton?: Skeleton ) Parameters Name Type Description entity entityThe entity to set the skeleton of. skeleton Skeleton?Skeleton to set, or nil to remove the entity's skeleton.
Entity.getMaterialSlotCount Gets the number of material slots in the entity's mesh. Returns 0 if the entity has no mesh.
Entity.getMaterialSlotCount (entity: entity): number Parameters Name Type Description entity entityEntity to get the slot count of.
Returns Name Type Description slotCount numberNumber of material slots available.
Entity.getMaterial Gets the material of an entity. Use getMaterialSlotCount to check how many material slots are available.
Entity.getMaterial (entity: entity, slot: number): Material Parameters Name Type Description entity entityThe entity to get the material of. slot numberThe 1-indexed material slot to read from.
Returns Name Type Description material MaterialMaterial of the entity in the given slot.
Entity.setMaterial Sets the material of an entity. Use getMaterialSlotCount to check how many material slots are available.
Entity.setMaterial (entity: entity, slot: number, material: Material ) Parameters Name Type Description entity entityThe entity to set the material of. slot numberThe 1-indexed material slot to write to. material MaterialMaterial to set.
Entity.getName Gets the name of an entity.
Entity.getName (entity: entity): string? Parameters Name Type Description entity entityThe entity to get the name of.
Returns Name Type Description name string?The name of the entity.
Entity.setName Sets the name of an entity.
Entity.setName (entity: entity, name: string) Parameters Name Type Description entity entityThe entity to set the name of. name stringThe name to set.
Types Position, orientation and scale.
type Transform = { .position: vector, .orientation: Quaternion , .scale: vector } Properties Field Type Description position vectorNo description orientation QuaternionNo description scale vectorNo description