entity
entity
The entity class is the central gameplay object in Stranded III, representing all items, objects, units, players, buildings, and interactive world elements.
It provides static methods on the entity global table (e.g. entity.get(id), entity.spawn(...)), instance methods on entity objects (e.g. e:setDefinition(...), e:getChildren()), and supports attaching event lifecycle hooks in definition tables (e.g. onHit, onUse, onDestroy).
Overview
Properties (11)
| Property | Type | Summary |
|---|---|---|
childCount
|
number
|
Total child entity count accounting for item stack counts. |
def
|
entitydef
|
The entity definition descriptor. |
hasChildren
|
boolean
|
Checks if the entity has any child entities. |
hasInstance
|
boolean
|
Checks if the entity has an active Godot visual scene instance. |
hasParent
|
boolean
|
Checks if the entity has a parent entity. |
id
|
number
|
The unique runtime integer ID of the entity. |
instanceNode
|
node
|
The visual Godot scene Node wrapper of the entity. |
isValid
|
boolean
|
Checks whether the entity instance is valid. |
position
|
vector3
|
3D world position coordinates. |
rotation
|
vector3
|
3D Euler rotation angles in degrees. |
scale
|
vector3
|
3D scale vector. |
Methods (61)
| Method Signature | Returns | Summary |
|---|---|---|
entity.addState(entity, stateDef, [value], [duration])
|
boolean
|
Applies a buff/debuff state to an entity. |
entity.countInBox(position, size, [def], [limit])
|
number
|
Counts entities within a bounding box. |
entity.countInRadius(position, radius, [def], [limit])
|
number
|
Counts entities within a spherical radius. |
entity.damage(entity, damage)
|
void
|
Inflicts damage to an entity. |
entity.exists(val)
|
boolean
|
Checks if an entity exists in the world. |
entity:findNode(name, [recursive = true])
|
node
|
Finds a child node by name within the entity scene hierarchy. |
entity.get(val)
|
entity
|
Looks up an entity by runtime ID. |
entity:getAabb([global = false])
|
aabb
|
Calculates the bounding box enclosing all entity meshes. |
entity:getAabbByMaterial(material, [global = false])
|
aabb
|
Calculates the bounding box of surfaces using the specified material. |
entity:getAabbByTexture(textureName, [global = false])
|
aabb
|
Calculates the bounding box of surfaces using the specified texture. |
entity:getAnimationPlayers()
|
table
|
Gets all AnimationPlayer nodes in the entity. |
entity:getAttributeF(attributeDef)
|
number
|
Gets a float attribute value. |
entity:getAttributeI(attributeDef)
|
number
|
Gets an integer attribute value. |
entity:getAttributeS(attributeDef)
|
string
|
Gets a string attribute value. |
entity:getAudioNodes()
|
table
|
Gets all positional audio player nodes in the entity. |
entity:getChild(index)
|
entity
|
Gets a direct child entity by 1-based index. |
entity.getChildCount(val, [stackCount = true])
|
number
|
Counts children of the specified entity. |
entity.getChildOfType(parent, def, [recursive = false])
|
number
|
Finds the first child entity matching a definition ID. |
entity:getChildren()
|
table
|
Gets all direct child entities. |
entity:getColliderNodes()
|
table
|
Gets all collision shape and collision object nodes in the entity. |
entity:getFinalAttribute(attributeDef)
|
number
|
Gets the final attribute value with states applied. |
entity.getInBox(position, size, [def])
|
table
|
Finds all entities within a bounding box. |
entity.getInRadius(position, radius, [def])
|
table
|
Finds all entities within a spherical radius. |
entity:getInstanceNode()
|
node
|
Gets the Godot scene root Node of the entity instance. |
entity:getLightNodes()
|
table
|
Gets all Light3D nodes in the entity. |
entity:getLocalAabb()
|
aabb
|
Gets the local-space bounding box of the entity. |
entity:getMaterialNames()
|
table
|
Gets the resource names of all materials on the entity. |
entity:getMaterials()
|
table
|
Gets all unique material definitions used by the entity. |
entity:getMeshNodes()
|
table
|
Gets all MeshInstance3D nodes in the entity hierarchy. |
entity:getNodes([typeName], [recursive = true])
|
table
|
Returns all child nodes optionally filtered by class type. |
entity:getParent()
|
entity
|
Gets the parent entity. |
entity:getParticleNodes()
|
table
|
Gets all particle emitter nodes in the entity. |
entity:getPartsByMaterial(material)
|
table
|
Finds child mesh nodes that use the specified material. |
entity:getPartsByTexture(textureName)
|
table
|
Finds child mesh nodes that use the specified texture. |
entity:getRawAttributeF(attributeDef)
|
number
|
Gets the raw float attribute value without state buffs. |
entity:getRawAttributeI(attributeDef)
|
number
|
Gets the raw integer attribute value without state buffs. |
entity:getRawAttributeS(attributeDef)
|
string
|
Gets the raw string attribute value. |
entity.getState(entity, stateDef)
|
state
|
Gets an active state wrapper on the entity. |
entity.getStates(entity)
|
table
|
Returns all active states on the entity. |
entity:getSurfacePosition()
|
vector3
|
Gets the terrain ground position beneath the entity. |
entity:getTextures()
|
table
|
Gets the names of all textures used across entity mesh surfaces. |
entity:getWorldAabb()
|
aabb
|
Gets the world-space bounding box of the entity. |
entity:hasMaterial(material)
|
boolean
|
Checks if the entity uses a specific material. |
entity.hasState(entity, stateDef)
|
boolean
|
Checks if an entity has a specific active state. |
entity:hasTexture(textureName)
|
boolean
|
Checks if the entity uses a specific texture. |
entity:isChildActive(name, [recursive = true])
|
boolean
|
Checks if a child node is active. |
entity:remove()
|
boolean
|
Destroys and despawns the entity. |
entity.removeAllStates(entity)
|
boolean
|
Removes all states from the entity. |
entity:removeAttribute(attributeDef)
|
boolean
|
Removes an attribute override from the entity. |
entity.removeState(entity, stateDef, [invokeLua = true])
|
boolean
|
Removes a specific state from the entity. |
entity:setAttributeF(attributeDef, value)
|
void
|
Sets a float attribute on the entity. |
entity:setAttributeI(attributeDef, value)
|
void
|
Sets an integer attribute on the entity. |
entity:setAttributeS(attributeDef, value)
|
void
|
Sets a string attribute on the entity. |
entity:setChildActive(name, active, [recursive = true])
|
boolean
|
Enables or disables a child node by name. |
entity.setChildMeshVisible(entity, name, visible, [recursive = true])
|
boolean
|
Toggles visibility of a named child mesh node. |
entity:setDefinition(def)
|
boolean
|
Morphs the entity into a different definition. |
entity:setParent(parent, [isStoredOutside = false])
|
boolean
|
Attaches the entity to a parent entity. |
entity.spawn(def, position, [scale])
|
entity
|
Spawns an entity into the world. |
entity.spawnOnGround(def, position, [yRot = 0], [scale])
|
entity
|
Spawns an entity aligned on the ground surface. |
entity.store(item, parent, [amount = -1], [capacityLimit = false])
|
boolean
|
Stores an item entity into a container entity. |
entity:unparent()
|
boolean
|
Detaches the entity from its current parent. |
Hooks & Events (27)
| Hook Signature | Returns | Summary |
|---|---|---|
entity:onChangeChildren(entityId)
|
void
|
Triggered when children are added, removed, or stack count changes. |
entity:onChangeParent(entity, newParent, oldParent)
|
void
|
Triggered when the entity parent changes. |
entity:onChangeStates(entityId)
|
void
|
Triggered when status effects are added or removed. |
entity:onCollect(parentId, entityId)
|
boolean
|
Triggered when an item entity is collected into an inventory. |
entity:onCollision(entity, other, speed)
|
void
|
Triggered on physical collision with another object or terrain. |
entity:onConsume(consumer, entity)
|
boolean
|
Triggered when the entity is consumed (eaten or drunk). |
entity:onDamage(sourceId, targetId, weaponId, projectileIndex, hitPoint, damage, wasAlive)
|
boolean
|
Triggered during damage calculation. |
entity:onDestroy(entity)
|
boolean
|
Triggered when the entity is destroyed. |
entity:onFocus(entityId)
|
string|number|table|void
|
Triggered when the player crosshair aims at the entity. |
entity:onHide()
|
void
|
Triggered when the entity is hidden (e.g. chunk unloaded). |
entity:onHit(sourceId, targetId, weaponId, projectileIndex)
|
boolean
|
Triggered when the entity is struck by an attack or tool. |
entity:onHourTick(entityId)
|
void
|
Triggered every in-game hour for entities registered with hourly tick. |
entity:onImpact(entityId, velocity, isOnFloor, airTime)
|
void
|
Triggered on movement impact / landing from height. |
entity:onLiquidEnter(entity, liquidType)
|
void
|
Triggered when the entity enters water or liquid. |
entity:onLiquidLeave(entity)
|
void
|
Triggered when the entity leaves water or liquid. |
projectileDef:onProjectileImpact(spawnerId, targetId, weaponId, projectileIndex, position)
|
boolean
|
Triggered when a projectile strikes an entity or terrain. |
entity:onRandomSpawn(entity, position)
|
void
|
Triggered during procedural random map spawning. |
entity:onShow()
|
void
|
Triggered when the entity becomes active and visible (e.g. chunk loaded). |
entity:onSpawn()
|
void
|
Triggered when the entity is freshly created and spawned into the world. |
entity:onStateApply(stateDefIndex, value, duration, stateValue, stateRemainingDuration)
|
void
|
Triggered when a status effect is successfully applied to the entity. |
entity:onStateRemove(stateDefIndex, stateValue, stateRemainingDuration, isExpire)
|
boolean
|
Triggered when a status effect is removed or expires. |
entity:onStateTick(stateDefIndex, stateValue, stateDuration, stateRemainingDuration)
|
void
|
Periodic tick for states applied to the entity. |
entity:onStateTryApply(stateDefIndex, value, duration)
|
boolean
|
Entity-side check before applying a state. |
entity:onUpdate(entity, delta)
|
void
|
Periodic frame update hook for entities requiring active script ticking. |
entity:onUse(user, entity)
|
boolean
|
Triggered when the entity is used / interacted with. |
entity:onUseAlt(user, entity)
|
boolean
|
Triggered on secondary / alternate interaction. |
entity:onUseDead(userId, entityId)
|
boolean
|
Triggered when interacting with a dead unit. |
Detailed Reference
entity.childCountnumberCount of child entities including stacks.
Returns the sum of direct child entities taking item stack counts into account.
entity.defentitydefDefinition descriptor.
Provides access to the entity definition metadata (ID, display name, index).
entity.hasChildrenbooleantrue if entity contains children.
Returns true if the entity child collection is non-empty.
entity.hasInstancebooleantrue if visual scene node exists.
Entities in unloaded chunks or purely stored in inventories may not have an active visual scene node.
entity.hasParentbooleantrue if entity is attached to a parent.
Returns true if the entity is stored inside an inventory, container, or attached to another entity.
entity.idnumberUnique integer entity ID.
Every spawned entity has a unique positive integer ID throughout the session.
entity.instanceNodenodeRoot scene node wrapper, or nil.
Returns the node wrapper for the root scene node of this entity if instantiated.
entity.isValidbooleantrue if entity is alive and valid in world.
Returns true if the underlying C# entity is active and has not been destroyed.
entity.positionvector3Current world position.
Gets or sets the entity 3D world coordinates.
entity.rotationvector3Euler rotation angles in degrees.
Gets or sets rotation as Euler angles in degrees. Applying rotation updates the underlying Godot scene node.
entity.scalevector33D scale vector.
Gets or sets the local 3D scale.
entity.addState(entity, stateDef, [value], [duration])| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity. | |
stateDef | string|statedef | State definition ID or descriptor. | |
value | number | 0 | Custom state intensity / value (defaults to state definition value). |
duration | number | 0 | Custom duration in seconds (defaults to state definition duration). |
booleantrue if state was successfully applied.
Applies a status effect (e.g. poison, burning, wet) to the entity.
entity.addState(playerEntity, "poison", 10, 30)entity.countInBox(position, size, [def], [limit])| Parameter | Type | Default | Description |
|---|---|---|---|
position | vector3 | Origin corner. | |
size | vector3 | Box dimensions. | |
def | entitydef | optional | Filter by definition. |
limit | number | 0 | Maximum count to check. |
numberTotal entities found.
Counts entities within an axis-aligned bounding box.
entity.countInRadius(position, radius, [def], [limit])| Parameter | Type | Default | Description |
|---|---|---|---|
position | vector3 | Center position. | |
radius | number | Search radius. | |
def | entitydef | optional | Filter by definition. |
limit | number | 0 | Maximum count to check. |
numberTotal entities found.
Counts entities within distance radius of position.
entity.damage(entity, damage)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity ID or object. | |
damage | number | Damage amount. |
Applies direct damage to the target entity, invoking damage hooks and triggering destruction if health reaches 0.
entity.exists(val)| Parameter | Type | Default | Description |
|---|---|---|---|
val | number|entity | Entity ID or entity object. |
booleantrue if entity exists.
Returns true if the specified entity ID or object exists and is active.
entity:findNode(name, [recursive = true])| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | Child node name. | |
recursive | boolean | `true` | Search all descendants. |
nodeChild node, or nil if not found.
Searches the entity scene tree for a child node with the specified name.
entity.get(val)| Parameter | Type | Default | Description |
|---|---|---|---|
val | number|entity | Entity ID integer or existing entity wrapper. |
entityEntity instance, or nil if not found.
Retrieves a live entity by its integer ID.
local e = entity.get(42)
if e and e.isValid then
print("Found entity with definition: " .. e.def.id)
endentity:getAabb([global = false])| Parameter | Type | Default | Description |
|---|---|---|---|
global | boolean | `false` | Whether to return global world bounds. |
aabbCombined bounding box of all meshes.
Computes the Axis-Aligned Bounding Box enclosing all visible meshes on the entity.
entity:getAabbByMaterial(material, [global = false])| Parameter | Type | Default | Description |
|---|---|---|---|
material | string|materialdef | Target material. | |
global | boolean | `false` | World coordinates if true. |
aabbBounding box of surfaces with that material, or nil.
Calculates the bounding box restricted only to surfaces that render with material.
entity:getAabbByTexture(textureName, [global = false])| Parameter | Type | Default | Description |
|---|---|---|---|
textureName | string | Target texture name. | |
global | boolean | `false` | World coordinates if true. |
aabbBounding box of surfaces with that texture, or nil.
Calculates the bounding box restricted only to surfaces that use textureName.
entity:getAnimationPlayers()table1-based array of AnimationPlayer nodes.
Returns all animation players on the entity.
entity:getAttributeF(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
numberFloat attribute value.
Reads the float attribute value stored on the entity.
entity:getAttributeI(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
numberInteger attribute value.
Reads the integer attribute value stored on the entity.
entity:getAttributeS(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
stringString attribute value.
Reads the string attribute value stored on the entity.
entity:getAudioNodes()table1-based array of AudioStreamPlayer3D nodes.
Returns all 3D audio players attached to the entity.
entity:getChild(index)| Parameter | Type | Default | Description |
|---|---|---|---|
index | number | 1-based child index. |
entityChild entity, or nil if index is out of range.
Returns the child entity at the specified index.
entity.getChildCount(val, [stackCount = true])| Parameter | Type | Default | Description |
|---|---|---|---|
val | number|entity | Entity ID or object. | |
stackCount | boolean | `true` | Whether to sum item stack counts. |
numberNumber of children.
Returns the number of child entities attached to val.
entity.getChildOfType(parent, def, [recursive = false])| Parameter | Type | Default | Description |
|---|---|---|---|
parent | number|entity | Parent entity. | |
def | string|entitydef | Child definition ID to search for. | |
recursive | boolean | `false` | Whether to search sub-inventories. |
numberEntity ID of matching child, or 0 if none found.
Searches children of parent for an entity with definition def.
entity:getChildren()table1-based array of child entity objects.
Returns a table containing all child entities stored in or attached to this entity.
entity:getColliderNodes()table1-based array of collision nodes.
Returns collision nodes associated with the entity.
entity:getFinalAttribute(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
numberEffective calculated attribute value.
Calculates the effective attribute value factoring in base definitions, instance overrides, and active status buffs/debuffs.
entity.getInBox(position, size, [def])| Parameter | Type | Default | Description |
|---|---|---|---|
position | vector3 | Origin corner. | |
size | vector3 | Box dimensions. | |
def | entitydef | optional | Filter by definition. |
table1-based array of entity instances.
Returns a table of all entities inside the specified axis-aligned bounding box.
entity.getInRadius(position, radius, [def])| Parameter | Type | Default | Description |
|---|---|---|---|
position | vector3 | Center position. | |
radius | number | Search radius. | |
def | entitydef | optional | Filter by definition. |
table1-based array of entity instances.
Returns a table of all entities within radius of position.
local items = entity.getInRadius(player.position, 5.0)entity:getInstanceNode()nodeVisual scene root node wrapper.
Returns the node wrapper for the visual 3D scene instance of the entity.
entity:getLightNodes()table1-based array of Light3D nodes.
Returns all light sources attached to the entity.
entity:getLocalAabb()aabbLocal bounding box.
Shortcut for entity:getAabb(false).
entity:getMaterialNames()tableArray of material resource name strings.
Returns the names of all materials attached to mesh surfaces.
entity:getMaterials()tableTable of unique materialdef descriptors.
Inspects all mesh surfaces and returns the unique material definitions.
entity:getMeshNodes()table1-based array of MeshInstance3D node wrappers.
Returns all 3D mesh instances that compose this entity.
entity:getNodes([typeName], [recursive = true])| Parameter | Type | Default | Description |
|---|---|---|---|
typeName | string | "" | Class type filter (e.g. |
recursive | boolean | `true` | Search all descendants. |
table1-based array of node wrappers.
Searches the entity visual hierarchy for nodes matching the specified class type.
entity:getParent()entityParent entity, or nil.
Returns the parent entity containing or holding this entity.
entity:getParticleNodes()table1-based array of particle emitter nodes.
Returns GPUParticles3D and CPUParticles3D nodes attached to the entity.
entity:getPartsByMaterial(material)| Parameter | Type | Default | Description |
|---|---|---|---|
material | string|materialdef | Material ID or definition. |
tableArray of matching node wrappers.
Returns mesh nodes that render with material.
entity:getPartsByTexture(textureName)| Parameter | Type | Default | Description |
|---|---|---|---|
textureName | string | Texture name. |
tableArray of matching node wrappers.
Returns mesh nodes that render with textureName.
entity:getRawAttributeF(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
numberUnmodified float attribute value.
Returns the raw attribute value stored on the entity instance.
entity:getRawAttributeI(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
numberUnmodified integer attribute value.
Returns the raw integer attribute value.
entity:getRawAttributeS(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
stringUnmodified string attribute value.
Returns the raw string attribute value.
entity.getState(entity, stateDef)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity. | |
stateDef | string|statedef | State definition. |
stateActive state wrapper, or invalid state wrapper if not present.
Looks up the active status effect instance matching stateDef on the entity.
entity.getStates(entity)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity. |
table1-based array of active state objects.
Returns a table containing all currently applied status effects.
entity:getSurfacePosition()vector33D ground coordinates directly beneath entity.
Calculates the terrain surface coordinate at the entity X and Z coordinates.
entity:getTextures()tableArray of texture name strings.
Returns texture file names referenced by mesh materials.
entity:getWorldAabb()aabbWorld-space bounding box.
Shortcut for entity:getAabb(true).
entity:hasMaterial(material)| Parameter | Type | Default | Description |
|---|---|---|---|
material | string|materialdef | Material ID or definition to check. |
booleantrue if entity uses the material.
Tests whether any mesh surface on the entity uses the specified material.
entity.hasState(entity, stateDef)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity. | |
stateDef | string|statedef | State definition. |
booleantrue if entity currently has the state.
Returns true if the state is currently applied.
entity:hasTexture(textureName)| Parameter | Type | Default | Description |
|---|---|---|---|
textureName | string | Texture name to look for. |
booleantrue if texture is used.
Tests whether any surface uses textureName.
entity:isChildActive(name, [recursive = true])| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | Child node name. | |
recursive | boolean | `true` | Search all descendants. |
booleantrue if child node exists and is active.
Returns true if the named child node is active in the scene hierarchy.
entity:remove()booleantrue if removed successfully.
Deletes the entity from the world and cleans up all scene nodes.
entity.removeAllStates(entity)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity. |
booleantrue if any states were removed.
Clears all active status effects on the target entity.
entity:removeAttribute(attributeDef)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. |
booleantrue if attribute was present and removed.
Removes the instance attribute override, resetting behavior to default definitions.
entity.removeState(entity, stateDef, [invokeLua = true])| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity. | |
stateDef | string|statedef | State definition. | |
invokeLua | boolean | `true` | Whether to fire |
booleantrue if state was found and removed.
Removes the status effect from the target entity.
entity:setAttributeF(attributeDef, value)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. | |
value | number | Float value to assign. |
Assigns a float attribute value (e.g. custom durability, health).
entity:setAttributeI(attributeDef, value)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. | |
value | number | Integer value to assign. |
Assigns an integer attribute value.
entity:setAttributeS(attributeDef, value)| Parameter | Type | Default | Description |
|---|---|---|---|
attributeDef | attributedef | Attribute descriptor. | |
value | string | String value to assign. |
Assigns a string attribute value.
entity:setChildActive(name, active, [recursive = true])| Parameter | Type | Default | Description |
|---|---|---|---|
name | string | Child node name. | |
active | boolean | Active state. | |
recursive | boolean | `true` | Search all descendants. |
booleantrue if node was found and updated.
Toggles active processing and visibility for the named child node.
entity.setChildMeshVisible(entity, name, visible, [recursive = true])| Parameter | Type | Default | Description |
|---|---|---|---|
entity | number|entity | Target entity. | |
name | string | Child node name. | |
visible | boolean | Visibility state. | |
recursive | boolean | `true` | Search descendants. |
booleantrue if node was found and updated.
Finds a child node by name and sets its active/visible state.
entity:setDefinition(def)| Parameter | Type | Default | Description |
|---|---|---|---|
def | string|entitydef | New definition ID or descriptor. |
booleantrue if definition was morphed successfully.
Dynamically changes the definition of an entity instance (e.g. growing a plant from stage 1 to stage 2).
e:setDefinition("apple_tree_grown")entity:setParent(parent, [isStoredOutside = false])| Parameter | Type | Default | Description |
|---|---|---|---|
parent | entity|number|nil | New parent entity or nil to unparent. | |
isStoredOutside | boolean | `false` | Whether item remains visible outside. |
booleantrue if reparenting succeeded.
Reparents the entity to parent.
entity.spawn(def, position, [scale])| Parameter | Type | Default | Description |
|---|---|---|---|
def | string|entitydef | Entity definition ID or descriptor. | |
position | vector3 | 3D world spawn position. | |
scale | vector3 | `(1, 1, 1)` | Scale vector. |
entityThe spawned entity, or nil on failure.
Spawns a new entity of definition def at the given 3D coordinates.
local stone = entity.spawn("stone", vector3.new(0, 10, 0))entity.spawnOnGround(def, position, [yRot = 0], [scale])| Parameter | Type | Default | Description |
|---|---|---|---|
def | string|entitydef | Entity definition ID or descriptor. | |
position | vector3 | Horizontal world position. | |
yRot | number | `0` | Yaw rotation in degrees. |
scale | vector3 | `(1, 1, 1)` | Scale vector. |
entityThe spawned entity aligned with terrain ground.
Calculates the ground height and slope at position and spawns the entity aligned to the terrain.
entity.store(item, parent, [amount = -1], [capacityLimit = false])| Parameter | Type | Default | Description |
|---|---|---|---|
item | number|entity | Item entity to store. | |
parent | number|entity | Container or inventory parent entity. | |
amount | number | `-1` | Quantity to store (-1 for entire stack). |
capacityLimit | boolean | `false` | Whether to enforce container weight/capacity limits. |
booleantrue if stored successfully.
Moves item into the inventory of parent.
entity:unparent()booleantrue if detached successfully.
Unparents the entity, placing it directly into the world root.
entity:onChangeChildren(entityId)| Parameter | Type | Default | Description |
|---|---|---|---|
entityId | number | Entity ID whose children changed. |
Called whenever the child collection or stack sizes of this entity change.
entity:onChangeParent(entity, newParent, oldParent)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | entity | The entity reparented. | |
newParent | entity|nil | New parent entity or nil. | |
oldParent | entity|nil | Old parent entity or nil. |
Called when an entity is picked up into an inventory, transferred between containers, or dropped.
entity:onChangeStates(entityId)| Parameter | Type | Default | Description |
|---|---|---|---|
entityId | number | Entity ID whose states changed. |
Called when the state list of the entity is modified.
entity:onCollect(parentId, entityId)| Parameter | Type | Default | Description |
|---|---|---|---|
parentId | number | Collector entity ID (e.g. player). | |
entityId | number | Collected item entity ID. |
booleanReturn true to cancel collection.
Called when picked up by a player or unit.
entity:onCollision(entity, other, speed)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | entity | This entity. | |
other | entity|nil | The colliding entity, or nil if terrain/static. | |
speed | number | Impact velocity speed. |
Called when an entity collides with another entity or surface.
entity:onConsume(consumer, entity)| Parameter | Type | Default | Description |
|---|---|---|---|
consumer | entity | The unit consuming the entity. | |
entity | entity | The consumed item. |
booleanReturn true if consumed successfully.
Called when consuming food, medicine, or potions.
entity:onDamage(sourceId, targetId, weaponId, projectileIndex, hitPoint, damage, wasAlive)| Parameter | Type | Default | Description |
|---|---|---|---|
sourceId | number | Attacking entity ID. | |
targetId | number | Damaged entity ID. | |
weaponId | number | Weapon entity ID. | |
projectileIndex | number | Projectile index or 0. | |
hitPoint | vector3 | 3D hit point. | |
damage | number | Calculated damage. | |
wasAlive | boolean | Whether entity was alive before damage. |
booleanReturn true to prevent damage from applying.
Called when damage is about to be inflicted on the entity.
entity:onDestroy(entity)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | entity | The entity being destroyed. |
booleanReturn true to cancel destruction.
Called when the entity is broken, depleted, or killed.
entity:onFocus(entityId)| Parameter | Type | Default | Description |
|---|---|---|---|
entityId | number | Entity ID being focused by player reticle. |
string|number|table|voidOptional custom text or controls info to display on crosshair.
Called when the HUD reticle points at this entity. Can return custom interaction prompt text.
entity:onHide()Called when the entity is hidden or its chunk is unloaded.
entity:onHit(sourceId, targetId, weaponId, projectileIndex)| Parameter | Type | Default | Description |
|---|---|---|---|
sourceId | number | Entity ID of attacker / source. | |
targetId | number | Entity ID of target entity. | |
weaponId | number | Entity ID of weapon used, or 0. | |
projectileIndex | number | Projectile index if hit by projectile, or 0. |
booleanReturn true to cancel default hit handling and damage.
Called when the entity is hit. Common hook for harvesting plants, mining rocks, or custom hit reactions.
def.object.banana_plant.onHit = function(sourceId, targetId, weaponId, projectileIndex)
grow(targetId, 2)
endentity:onHourTick(entityId)| Parameter | Type | Default | Description |
|---|---|---|---|
entityId | number | Entity ID. |
Called on in-game hourly changes for plants, spoiled food, or time-dependent objects.
entity:onImpact(entityId, velocity, isOnFloor, airTime)| Parameter | Type | Default | Description |
|---|---|---|---|
entityId | number | Entity ID. | |
velocity | vector3 | Landing velocity vector. | |
isOnFloor | boolean | Whether landed on ground. | |
airTime | number | Time in seconds spent airborne. |
Called when a unit or object hits the ground after falling (e.g. for fall damage or landing sounds).
entity:onLiquidEnter(entity, liquidType)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | entity | This entity. | |
liquidType | number | Terrain liquid type enum (e.g. water, lava). |
Called when entering a body of water or other terrain liquid.
entity:onLiquidLeave(entity)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | entity | This entity. |
Called when stepping or emerging out of liquid.
projectileDef:onProjectileImpact(spawnerId, targetId, weaponId, projectileIndex, position)| Parameter | Type | Default | Description |
|---|---|---|---|
spawnerId | number | Shooter unit ID. | |
targetId | number | Target entity ID, or 0 if hit terrain. | |
weaponId | number | Weapon entity ID. | |
projectileIndex | number | Projectile index. | |
position | vector3 | 3D impact position. |
booleanReturn true to prevent default projectile destruction.
Declared on projectile entity definitions (e.g. arrows, thrown stones).
entity:onRandomSpawn(entity, position)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | entity | Newly created entity. | |
position | vector3 | Spawn position. |
Called when the entity is generated during procedural world generation or cluster spawning.
entity:onShow()Called when the chunk containing the entity is loaded and the entity is shown.
entity:onSpawn()Invoked immediately after the entity is spawned in the game world.
def.item.flare.onSpawn = function(self)
print("Flare spawned: " .. self.id)
endentity:onStateApply(stateDefIndex, value, duration, stateValue, stateRemainingDuration)| Parameter | Type | Default | Description |
|---|---|---|---|
stateDefIndex | number | Index of state definition. | |
value | number | Applied value. | |
duration | number | Applied duration. | |
stateValue | number | Current state value. | |
stateRemainingDuration | number | Remaining duration. |
Called immediately after a state is attached to the entity.
entity:onStateRemove(stateDefIndex, stateValue, stateRemainingDuration, isExpire)| Parameter | Type | Default | Description |
|---|---|---|---|
stateDefIndex | number | Index of state definition. | |
stateValue | number | State value. | |
stateRemainingDuration | number | Remaining duration. | |
isExpire | boolean | True if state expired naturally. |
booleanReturn true to cancel state removal.
Called before removing a state from the entity.
entity:onStateTick(stateDefIndex, stateValue, stateDuration, stateRemainingDuration)| Parameter | Type | Default | Description |
|---|---|---|---|
stateDefIndex | number | Index of state definition. | |
stateValue | number | Current intensity value. | |
stateDuration | number | Total duration. | |
stateRemainingDuration | number | Remaining duration in seconds. |
Called every state tick interval (e.g. applying poison damage every second).
entity:onStateTryApply(stateDefIndex, value, duration)| Parameter | Type | Default | Description |
|---|---|---|---|
stateDefIndex | number | Index of state definition. | |
value | number | Proposed state value. | |
duration | number | Proposed state duration. |
booleanReturn true to prevent the state from being applied.
Allows an entity to be immune or resist specific status effects.
entity:onUpdate(entity, delta)| Parameter | Type | Default | Description |
|---|---|---|---|
entity | entity | This entity. | |
delta | number | Elapsed time in seconds since last frame. |
Invoked every frame for entities that declare onUpdate.
entity:onUse(user, entity)| Parameter | Type | Default | Description |
|---|---|---|---|
user | entity | The interacting player or unit. | |
entity | entity | The entity being used. |
booleanReturn true to cancel default use / inventory loot behavior.
Called when the player presses the interaction key on this entity.
entity:onUseAlt(user, entity)| Parameter | Type | Default | Description |
|---|---|---|---|
user | entity | Interacting unit. | |
entity | entity | Target entity. |
booleanReturn true if handled.
Called when secondary interaction occurs (e.g. right click or alternate use binding).
entity:onUseDead(userId, entityId)| Parameter | Type | Default | Description |
|---|---|---|---|
userId | number | ID of the user. | |
entityId | number | ID of the dead entity. |
booleanReturn true to cancel default looting.
Called when looting a defeated animal or enemy.