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
The unique identifier for this entity.
Returns Entity |
addName
(
name
)
| |
addToMap
(
attribute
, value
)
| Parameters attribute: Intvalue: 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
The type ID of the attribute to search for.
Returns Sequence<Entity>
A sequence of entities that are children of this entity's attribute.
|
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
()
|
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
if the component does not exist for this entity.
|
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
True if the entity is local, false otherwise.
|
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
if the component does not exist for this entity.
|
readIntoComponent
(
cls
)
|
Signature
fun <T : ComponentBase> readIntoComponent(cls: Pair<T, Boolean>, Boolean>): T Parameters cls: Pair<T, Boolean>Returns Entity |
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
The name of the event to listen for.
listener: Function2
The function to call when the event is triggered.
|
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
The list of components to set.
|
setComponents
(
components
)
|
Sets the components for this entity.
Signature
fun setComponents(vararg components: ComponentBase): Entity Parameters |
setMap
(
attribute
, value
)
| Parameters attribute: Intvalue: HashMap<*, *> |
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 Entity?
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: IntReturns Entity? |
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
The list of components to add to the new entity.
|
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 Entity |
createPanelEntity
(
entityId
, panelId
, transform
, components
)
|
Signature
fun Entity.Companion.createPanelEntity(entityId: Int, panelId: Int, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns Entity |
fromBox
(
length
, transform
, material
, components
)
|
Signature
fun Entity.Companion.fromBox(length: Float, transform: Transform, material: Material? = null, vararg components: ComponentBase): Entity Parameters Returns Entity |
fromGLB
(
mesh
, transform
, components
)
|
Signature
fun Entity.Companion.fromGLB(mesh: Mesh, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns Entity |
fromMeshAndMaterial
(
mesh
, material
, transform
, components
)
|
Signature
fun Entity.Companion.fromMeshAndMaterial(mesh: Mesh, material: Material, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns Entity |
fromPanelRegistry
(
registry
, transform
, components
)
|
Signature
fun Entity.Companion.fromPanelRegistry(registry: PanelRegistration, transform: Transform, vararg components: ComponentBase): Entity Parameters Returns Entity |
fromSphere
(
length
, transform
, material
, components
)
|
Signature
fun Entity.Companion.fromSphere(length: Float, transform: Transform, material: Material? = null, vararg components: ComponentBase): Entity Parameters Returns Entity |
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 |