API reference
API reference
Select your platform
No SDKs available
No versions available

Entity

Entity

class Entity
Represents an entity in the spatial data model. Learn more about our Entity-Component-System (ECS) architecture here: https://developers.meta.com/horizon/documentation/spatial-sdk/spatial-sdk-ecs
It is recommended to use the Entity.create() static method to create new entities instead of the Entity constructors

Constructors

NameSummary
Entity
constructor(dataModel: DataModel, id: Long, vararg components: ComponentBase)

Constructor for creating an entity with a specified data model, ID, and variable number of components.

Types

NameSummary
Companion
object Companion

Functions

NameSummary
addName
fun Entity.addName(name: String): Entity
addToMap
fun addToMap(attribute: Int, value: <Error class: unknown class><out <Error class: unknown class>, out <Error class: unknown class>>)
childrenOfAttrId
fun childrenOfAttrId(typeID: Int): <Error class: unknown class><Entity>

childrenOfTypeId returns a sequence of entities that are children of this entity’s attribute.
destroy
fun destroy()

Destroys this entity.
destroyWithChildren
fun Entity.destroyWithChildren()
equals
open operator override fun equals(o: Any?): Boolean

Checks if this entity is equal to another object. The object is equal to this entity iff the object is an Entity and has the same ID as this entity.
getComponent
inline fun <T : ComponentBase> getComponent(recycler: ComponentRecyler? = null): T

gets the specified component with the most up to date attribute values for this entity. If the component does not exist for this entity, a RuntimeException will be thrown.
hasComponent
inline fun <T : ComponentBase> hasComponent(): Boolean
isLocal
fun isLocal(): Boolean

Returns whether the entity is local or not.
readIntoComponent
fun <T : ComponentBase> readIntoComponent(cls: <Error class: unknown class><T, Boolean>): T
registerEventListener
fun <T : EventArgs> registerEventListener(eventName: String, listener: (entity: Entity, eventArgs: T) -> Unit): Entity

Registers an event listener for a specific event.
setComponent
fun setComponent(c: ComponentBase): Entity

Sets a single component for this entity.
setComponents
fun setComponents(vararg components: ComponentBase): Entity

fun setComponents(components: List<ComponentBase>): Entity

Sets the components for this entity.
setMap
fun setMap(attribute: Int, value: <Error class: unknown class><out <Error class: unknown class>, out <Error class: unknown class>>)
tryGetComponent
inline fun <T : ComponentBase> tryGetComponent(recycler: ComponentRecyler? = null): T?

A safe way to get a component with the most up to date attribute values for this entity. If the component does not exist for this entity, null will be returned
tryReadIntoComponent
fun <T : ComponentBase> tryReadIntoComponent(cls: <Error class: unknown class><T, Boolean>, componentTypeID: Int): T?

Companion

object Companion

Functions

NameSummary
create
fun create(): Entity

Creates a new entity with the default data model.



fun create(component: ComponentBase): Entity

Creates a new entity with the specified component.



fun create(dm: DataModel): Entity

Creates a new entity with the specified data model.



fun create(vararg components: ComponentBase): Entity

Creates a new entity with the specified variable number of components.



fun create(components: List<ComponentBase>): Entity

Creates a new entity with the specified list of components.
createPanelEntity
fun Entity.Companion.createPanelEntity(panelId: Int, transform: Transform, vararg components: ComponentBase): Entity

fun Entity.Companion.createPanelEntity(entityId: Int, panelId: Int, transform: Transform, vararg components: ComponentBase): Entity
fromBox
fun Entity.Companion.fromBox(length: Float, transform: Transform, material: Material? = null, vararg components: ComponentBase): Entity
fromGLB
fun Entity.Companion.fromGLB(mesh: Mesh, transform: Transform, vararg components: ComponentBase): Entity
fromMeshAndMaterial
fun Entity.Companion.fromMeshAndMaterial(mesh: Mesh, material: Material, transform: Transform, vararg components: ComponentBase): Entity
fromPanelRegistry
fun Entity.Companion.fromPanelRegistry(registry: PanelRegistration, transform: Transform, vararg components: ComponentBase): Entity
fromSphere
fun Entity.Companion.fromSphere(length: Float, transform: Transform, material: Material? = null, vararg components: ComponentBase): Entity
nullEntity
fun nullEntity(): Entity

Creates a null entity. You cannot use this entity to set or get components. The nullEntity is generally used as a placeholder for Entity attributes.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon