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

DataModel

DataModel

class DataModel(dataModel_: Long)
DataModel is a class that manages data for Entities, Components, and Attributes in the Spatial SDK ECS architecture.
For debugging and introspecting into the live state of your datamodel, register the com.meta.spatial.datamodelinspector.DataModelInspectorFeature.
The DataModel is also responsible for passing custom events to listeners. Example:
val dataModel = EntityContext.getDataModel()
// setup button event listener
button.entity.registerEventListener<EventArgs>("button") { _, _ ->
  // handle event
}
dataModel?.sendEvent(entity, "button", EventArgs("click", dataModel))
Also see the https://github.com/meta-quest/Meta-Spatial-SDK-Samples/tree/901965d952d89aef5c5d81d93e5a2b88d275799d/PhysicsSample for a more in depth example of registering custom event listeners.

Constructors

NameSummary
DataModel
constructor(dataModel_: Long)

Types

NameSummary
Companion
object Companion
inner class KeyIterator(dm_: DataModel, it_: Long)

Functions

NameSummary
createEntity
fun createEntity(): Entity

Creates a new entity in the data model.



fun createEntity(vararg components: ComponentBase): Entity

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

Creates a new entity in the data model with components.
deleteEntity
fun deleteEntity(eid: Long)

Deletes an entity from the data model. The entity will be included in deleted queries next tick. We recommend using Entity.destroy() instead of this function.
getEventListenerForEvent
fun getEventListenerForEvent(eventType: String): Set<<Error class: unknown class><Entity, EventListener<EventArgs>>>

Gets all listeners registered for a specific event type.
getKeyValueMap
inline fun <T, V> getKeyValueMap(id: Long, attribute: Int): HashMap<T, V>
getLastUpdateVersion
fun getLastUpdateVersion(): <Error class: unknown class>

Experimental API. This gets a long that represents the last updated version of the data model.
hasKey
fun hasKey(id: Long, attribute: Int): Boolean

Checks if an entity has a specific attribute.
nativeGetKeyValueMap
external fun nativeGetKeyValueMap(dataModel: Long, id: Long, attribute: Int): Array<Any>
registerAttributeListener
fun registerAttributeListener(attribute: Int, listener: AttributeListener)

Registers a listener for changes to a specific attribute.
registerComponentListener
fun registerComponentListener(componentID: Int, componentClass: KClass<*>, listener: ComponentListener)

Registers a listener for changes to a specific component.
registerEventListener
fun registerEventListener(entity: Entity, eventType: String, listener: EventListener<EventArgs>)

Registers a listener for events on a specific entity.
registerLinkedEntityAttribute
fun registerLinkedEntityAttribute(attributeID: Int)

This method is experimental and is subject to change in the future.
removeComponentListener
fun removeComponentListener(componentID: Int)

Removes a previously registered component listener.

Companion

object Companion

Functions

NameSummary
getLocalDataModelTime
fun getLocalDataModelTime(): Long

Gets the local time based on the data model.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon