Entity.create() static method to create new entities instead of the Entity constructors
class Entity
Entity
(
dataModel
, id
, components
)
|
Constructor for creating an entity with a specified data model, ID, and variable number of components.
Signature
constructor(dataModel: DataModel, id: Long, vararg components: ComponentBase) Parameters
id:
Long
Returns |
addName
(
name
)
| |
addToMap
(
attribute
, value
)
| Parameters
attribute:
Int
value:
HashMap<*, *>
|
childrenOfAttrId
(
typeID
)
|
childrenOfTypeId returns a sequence of entities that are children of this entity's attribute.
Signature
fun childrenOfAttrId(typeID: Int): Sequence<Entity> Parameters
typeID:
Int
Returns
Sequence<Entity>
|
destroy
()
|
Destroys this entity.
This method will remove the entity from the data model and free up any resources associated with it.
Signature
fun destroy() |
destroyWithChildren
()
|
Recursively destroys this entity and all of its children in the entity hierarchy.
This function traverses the entity tree using TransformParent relationships and destroys all child entities before destroying the parent entity itself.
Signature
fun Entity.destroyWithChildren() |
equals
(
o
)
|
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.
Signature
open operator override fun equals(o: Any?): Boolean Parameters
o:
Any?
Returns
Boolean
|
getComponent
(
recycler
)
|
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.
Example:
val transform = entity.getComponent<Transform>()
Signature
inline fun <T : ComponentBase> getComponent(recycler: ComponentRecyler? = null): T Parameters
recycler:
ComponentRecyler?
Throws
RuntimeException
|
getComponentsDebugString
()
|
Returns a debug string listing all components attached to this entity and their values.
This method iterates through all registered component types and checks if this entity has each one. For components that exist, it reads the component data and includes its toString() output.
Note: This is a relatively expensive operation as it queries all registered component types.
Signature
fun getComponentsDebugString(): String Returns
String
|
hasComponent
()
|
Signature
inline fun <T : ComponentBase> hasComponent(): Boolean Returns
Boolean
|
isLocal
()
|
Returns whether the entity is local or not.
Signature
fun isLocal(): Boolean Returns
Boolean
|
markComponentChanged
()
|
Marks a component as "changed" without setting new component data.
This is useful in rare cases where you want the component to be considered "changed" for change detection purposes, even when the actual component data hasn't been modified. This will trigger component change listeners and queries that look for changed components.
Example:
// Force the Panel component to be marked as changed entity.markComponentChanged<Panel>()
Signature
inline fun <T : ComponentBase> markComponentChanged(): Entity Throws
RuntimeException
|
readIntoComponent
(
cls
)
|
Signature
fun <T : ComponentBase> readIntoComponent(cls: Pair<T, Boolean>, Boolean>): T Parameters
cls:
Pair<T, Boolean>
Returns |
registerEventListener
(
eventName
, listener
)
|
Registers an event listener for a specific event.
Signature
fun <T : EventArgs> registerEventListener(eventName: String, listener: (entity: Entity, eventArgs: T) -> Unit): Entity Parameters
eventName:
String
listener:
Function2
|
removeComponent
()
|
Removes a component from this entity.
This method removes the specified component and all its associated attributes from this entity. After removal, the entity will no longer have this component, and queries that filter by this component will no longer match this entity.
Example:
// Remove the Grabbable component from an entity entity.removeComponent<Grabbable>()
Signature
inline fun <T : ComponentBase> removeComponent(): Entity Throws
RuntimeException
|
requireComponent
(
errorMessage
)
|
Gets a required component with a custom error message.
This is a generic utility for scenarios where a component is absolutely required and missing it should result in a detailed error. Unlike tryGetComponent which returns null, this method throws a RuntimeException with your custom error message.
Example:
val transform = entity.requireComponent<Transform>(
"Transform required for physics simulation"
)
Signature
inline fun <T : ComponentBase> requireComponent(errorMessage: String): T Parameters
errorMessage:
String
Throws
RuntimeException
|
setComponent
(
c
)
|
Sets a single component for this entity.
Signature
fun setComponent(c: ComponentBase): Entity Parameters |
setComponents
(
components
)
|
Sets the components for this entity.
Signature
fun setComponents(components: List<ComponentBase>): Entity Parameters
components:
List
|
setComponents
(
components
)
|
Sets the components for this entity.
Signature
fun setComponents(vararg components: ComponentBase): Entity Parameters |
setMap
(
attribute
, value
)
| Parameters
attribute:
Int
value:
HashMap<*, *>
|
toString
()
|
Returns a string representation of this entity including its ID and all components.
When EntityDebugInfo.captureCreationCallstack is enabled, this also includes the callstack from when the entity was created and the time alive since creation.
Example output:
Entity(id=42, components=[
Component{name: Transform, type: 123, {pose=...}},
Component{name: Mesh, type: 456, {uri=...}}
])
Signature
open override fun toString(): String Returns
String
|
tryGetComponent
(
recycler
)
|
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.
Example:
val transform = entity.tryGetComponent<Transform>()
Signature
inline fun <T : ComponentBase> tryGetComponent(recycler: ComponentRecyler? = null): T? Parameters
recycler:
ComponentRecyler?
Returns
The component instance of type T or null if the component does not exist for this entity
|
tryReadIntoComponent
(
cls
, componentTypeID
)
|
Signature
fun <T : ComponentBase> tryReadIntoComponent(cls: Pair<T, Boolean>, Boolean>, componentTypeID: Int): T? Parameters
cls:
Pair<T, Boolean>
componentTypeID:
Int
Returns |
tryRemoveComponent
()
|
Removes a component from this entity if it exists.
This method is a safe version of Entity.removeComponent that returns false if the component does not exist instead of throwing an exception.
Example:
// Try to remove the Grabbable component, returns false if not present val wasRemoved = entity.tryRemoveComponent<Grabbable>()
Signature
inline fun <T : ComponentBase> tryRemoveComponent(): Boolean Returns
Boolean
|
willBeDeleted
()
|
Checks if this entity will be deleted in the next frame.
Returns true if destroy() has been called on this entity in the current frame, but the entity hasn't been fully removed yet. The entity will be inaccessible starting in the next frame.
Signature
fun willBeDeleted(): Boolean Returns
Boolean
|
create
()
|
Creates a new entity with the default data model.
Signature
fun create(): Entity |
create
(
dm
)
| |
create
(
component
)
|
Creates a new entity with the specified component.
Signature
fun create(component: ComponentBase): Entity Parameters |
create
(
components
)
|
Creates a new entity with the specified list of components.
Signature
fun create(components: List<ComponentBase>): Entity Parameters
components:
List
|
create
(
components
)
|
Creates a new entity with the specified variable number of components.
Signature
fun create(vararg components: ComponentBase): Entity Parameters |
createPanelEntity
(
panelId
, transform
, components
)
|
Signature
fun Entity.Companion.createPanelEntity(panelId: Int, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns |
createPanelEntity
(
entityId
, panelId
, transform
, components
)
|
Signature
fun Entity.Companion.createPanelEntity(entityId: Int, panelId: Int, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns |
fromBox
(
length
, transform
, material
, components
)
|
Signature
fun Entity.Companion.fromBox(length: Float, transform: Transform, material: Material? = null, vararg components: ComponentBase): Entity Parameters Returns |
fromGLB
(
mesh
, transform
, components
)
|
Signature
fun Entity.Companion.fromGLB(mesh: Mesh, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns |
fromMeshAndMaterial
(
mesh
, material
, transform
, components
)
|
Signature
fun Entity.Companion.fromMeshAndMaterial(mesh: Mesh, material: Material, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns |
fromPanelRegistry
(
registry
, transform
, components
)
|
Signature
fun Entity.Companion.fromPanelRegistry(registry: PanelRegistration, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns |
fromSphere
(
length
, transform
, material
, components
)
|
Signature
fun Entity.Companion.fromSphere(length: Float, transform: Transform, material: Material? = null, vararg components: ComponentBase): Entity Parameters Returns |
nullEntity
()
|
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.
Here is an example using TransformParent:
val transformParent = myEntity.getComponent<TransformParent>() transformParent.parent = Entity.nullEntity() // This makes it as if no TransformParent is set. myEntity.setComponent(transformParent)
Signature
fun nullEntity(): Entity |