Dev » Lua API » entity
← Back to all classes

entity

World & Entities 11 Properties 61 Methods 27 Hooks

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

# childCount PROPERTY
entity.childCount
Total child entity count accounting for item stack counts.
Parameters
None
Returns
number

Count of child entities including stacks.

Description

Returns the sum of direct child entities taking item stack counts into account.

# def PROPERTY
entity.def
The entity definition descriptor.
Parameters
None
Returns
entitydef

Definition descriptor.

Description

Provides access to the entity definition metadata (ID, display name, index).

# hasChildren PROPERTY
entity.hasChildren
Checks if the entity has any child entities.
Parameters
None
Returns
boolean

true if entity contains children.

Description

Returns true if the entity child collection is non-empty.

# hasInstance PROPERTY
entity.hasInstance
Checks if the entity has an active Godot visual scene instance.
Parameters
None
Returns
boolean

true if visual scene node exists.

Description

Entities in unloaded chunks or purely stored in inventories may not have an active visual scene node.

# hasParent PROPERTY
entity.hasParent
Checks if the entity has a parent entity.
Parameters
None
Returns
boolean

true if entity is attached to a parent.

Description

Returns true if the entity is stored inside an inventory, container, or attached to another entity.

# id PROPERTY
entity.id
The unique runtime integer ID of the entity.
Parameters
None
Returns
number

Unique integer entity ID.

Description

Every spawned entity has a unique positive integer ID throughout the session.

# instanceNode PROPERTY
entity.instanceNode
The visual Godot scene Node wrapper of the entity.
Parameters
None
Returns
node

Root scene node wrapper, or nil.

Description

Returns the node wrapper for the root scene node of this entity if instantiated.

# isValid PROPERTY
entity.isValid
Checks whether the entity instance is valid.
Parameters
None
Returns
boolean

true if entity is alive and valid in world.

Description

Returns true if the underlying C# entity is active and has not been destroyed.

# position PROPERTY
entity.position
3D world position coordinates.
Parameters
None
Returns
vector3

Current world position.

Description

Gets or sets the entity 3D world coordinates.

# rotation PROPERTY
entity.rotation
3D Euler rotation angles in degrees.
Parameters
None
Returns
vector3

Euler rotation angles in degrees.

Description

Gets or sets rotation as Euler angles in degrees. Applying rotation updates the underlying Godot scene node.

# scale PROPERTY
entity.scale
3D scale vector.
Parameters
None
Returns
vector3

3D scale vector.

Description

Gets or sets the local 3D scale.

# addState METHOD
entity.addState(entity, stateDef, [value], [duration])
Applies a buff/debuff state to an entity.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity.

stateDefstring|statedef

State definition ID or descriptor.

valuenumber0

Custom state intensity / value (defaults to state definition value).

durationnumber0

Custom duration in seconds (defaults to state definition duration).

Returns
boolean

true if state was successfully applied.

Description

Applies a status effect (e.g. poison, burning, wet) to the entity.

entity.addState(playerEntity, "poison", 10, 30)
# countInBox METHOD
entity.countInBox(position, size, [def], [limit])
Counts entities within a bounding box.
Parameters
ParameterTypeDefaultDescription
positionvector3

Origin corner.

sizevector3

Box dimensions.

defentitydefoptional

Filter by definition.

limitnumber0

Maximum count to check.

Returns
number

Total entities found.

Description

Counts entities within an axis-aligned bounding box.

# countInRadius METHOD
entity.countInRadius(position, radius, [def], [limit])
Counts entities within a spherical radius.
Parameters
ParameterTypeDefaultDescription
positionvector3

Center position.

radiusnumber

Search radius.

defentitydefoptional

Filter by definition.

limitnumber0

Maximum count to check.

Returns
number

Total entities found.

Description

Counts entities within distance radius of position.

# damage METHOD
entity.damage(entity, damage)
Inflicts damage to an entity.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity ID or object.

damagenumber

Damage amount.

Returns
None (void)
Description

Applies direct damage to the target entity, invoking damage hooks and triggering destruction if health reaches 0.

# exists METHOD
entity.exists(val)
Checks if an entity exists in the world.
Parameters
ParameterTypeDefaultDescription
valnumber|entity

Entity ID or entity object.

Returns
boolean

true if entity exists.

Description

Returns true if the specified entity ID or object exists and is active.

# findNode METHOD
entity:findNode(name, [recursive = true])
Finds a child node by name within the entity scene hierarchy.
Parameters
ParameterTypeDefaultDescription
namestring

Child node name.

recursiveboolean`true`

Search all descendants.

Returns
node

Child node, or nil if not found.

Description

Searches the entity scene tree for a child node with the specified name.

# get METHOD
entity.get(val)
Looks up an entity by runtime ID.
Parameters
ParameterTypeDefaultDescription
valnumber|entity

Entity ID integer or existing entity wrapper.

Returns
entity

Entity instance, or nil if not found.

Description

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)
end
# getAabb METHOD
entity:getAabb([global = false])
Calculates the bounding box enclosing all entity meshes.
Parameters
ParameterTypeDefaultDescription
globalboolean`false`

Whether to return global world bounds.

Returns
aabb

Combined bounding box of all meshes.

Description

Computes the Axis-Aligned Bounding Box enclosing all visible meshes on the entity.

# getAabbByMaterial METHOD
entity:getAabbByMaterial(material, [global = false])
Calculates the bounding box of surfaces using the specified material.
Parameters
ParameterTypeDefaultDescription
materialstring|materialdef

Target material.

globalboolean`false`

World coordinates if true.

Returns
aabb

Bounding box of surfaces with that material, or nil.

Description

Calculates the bounding box restricted only to surfaces that render with material.

# getAabbByTexture METHOD
entity:getAabbByTexture(textureName, [global = false])
Calculates the bounding box of surfaces using the specified texture.
Parameters
ParameterTypeDefaultDescription
textureNamestring

Target texture name.

globalboolean`false`

World coordinates if true.

Returns
aabb

Bounding box of surfaces with that texture, or nil.

Description

Calculates the bounding box restricted only to surfaces that use textureName.

# getAnimationPlayers METHOD
entity:getAnimationPlayers()
Gets all AnimationPlayer nodes in the entity.
Parameters
None
Returns
table

1-based array of AnimationPlayer nodes.

Description

Returns all animation players on the entity.

# getAttributeF METHOD
entity:getAttributeF(attributeDef)
Gets a float attribute value.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
number

Float attribute value.

Description

Reads the float attribute value stored on the entity.

# getAttributeI METHOD
entity:getAttributeI(attributeDef)
Gets an integer attribute value.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
number

Integer attribute value.

Description

Reads the integer attribute value stored on the entity.

# getAttributeS METHOD
entity:getAttributeS(attributeDef)
Gets a string attribute value.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
string

String attribute value.

Description

Reads the string attribute value stored on the entity.

# getAudioNodes METHOD
entity:getAudioNodes()
Gets all positional audio player nodes in the entity.
Parameters
None
Returns
table

1-based array of AudioStreamPlayer3D nodes.

Description

Returns all 3D audio players attached to the entity.

# getChild METHOD
entity:getChild(index)
Gets a direct child entity by 1-based index.
Parameters
ParameterTypeDefaultDescription
indexnumber

1-based child index.

Returns
entity

Child entity, or nil if index is out of range.

Description

Returns the child entity at the specified index.

# getChildCount METHOD
entity.getChildCount(val, [stackCount = true])
Counts children of the specified entity.
Parameters
ParameterTypeDefaultDescription
valnumber|entity

Entity ID or object.

stackCountboolean`true`

Whether to sum item stack counts.

Returns
number

Number of children.

Description

Returns the number of child entities attached to val.

# getChildOfType METHOD
entity.getChildOfType(parent, def, [recursive = false])
Finds the first child entity matching a definition ID.
Parameters
ParameterTypeDefaultDescription
parentnumber|entity

Parent entity.

defstring|entitydef

Child definition ID to search for.

recursiveboolean`false`

Whether to search sub-inventories.

Returns
number

Entity ID of matching child, or 0 if none found.

Description

Searches children of parent for an entity with definition def.

# getChildren METHOD
entity:getChildren()
Gets all direct child entities.
Parameters
None
Returns
table

1-based array of child entity objects.

Description

Returns a table containing all child entities stored in or attached to this entity.

# getColliderNodes METHOD
entity:getColliderNodes()
Gets all collision shape and collision object nodes in the entity.
Parameters
None
Returns
table

1-based array of collision nodes.

Description

Returns collision nodes associated with the entity.

# getFinalAttribute METHOD
entity:getFinalAttribute(attributeDef)
Gets the final attribute value with states applied.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
number

Effective calculated attribute value.

Description

Calculates the effective attribute value factoring in base definitions, instance overrides, and active status buffs/debuffs.

# getInBox METHOD
entity.getInBox(position, size, [def])
Finds all entities within a bounding box.
Parameters
ParameterTypeDefaultDescription
positionvector3

Origin corner.

sizevector3

Box dimensions.

defentitydefoptional

Filter by definition.

Returns
table

1-based array of entity instances.

Description

Returns a table of all entities inside the specified axis-aligned bounding box.

# getInRadius METHOD
entity.getInRadius(position, radius, [def])
Finds all entities within a spherical radius.
Parameters
ParameterTypeDefaultDescription
positionvector3

Center position.

radiusnumber

Search radius.

defentitydefoptional

Filter by definition.

Returns
table

1-based array of entity instances.

Description

Returns a table of all entities within radius of position.

local items = entity.getInRadius(player.position, 5.0)
# getInstanceNode METHOD
entity:getInstanceNode()
Gets the Godot scene root Node of the entity instance.
Parameters
None
Returns
node

Visual scene root node wrapper.

Description

Returns the node wrapper for the visual 3D scene instance of the entity.

# getLightNodes METHOD
entity:getLightNodes()
Gets all Light3D nodes in the entity.
Parameters
None
Returns
table

1-based array of Light3D nodes.

Description

Returns all light sources attached to the entity.

# getLocalAabb METHOD
entity:getLocalAabb()
Gets the local-space bounding box of the entity.
Parameters
None
Returns
aabb

Local bounding box.

Description

Shortcut for entity:getAabb(false).

# getMaterialNames METHOD
entity:getMaterialNames()
Gets the resource names of all materials on the entity.
Parameters
None
Returns
table

Array of material resource name strings.

Description

Returns the names of all materials attached to mesh surfaces.

# getMaterials METHOD
entity:getMaterials()
Gets all unique material definitions used by the entity.
Parameters
None
Returns
table

Table of unique materialdef descriptors.

Description

Inspects all mesh surfaces and returns the unique material definitions.

# getMeshNodes METHOD
entity:getMeshNodes()
Gets all MeshInstance3D nodes in the entity hierarchy.
Parameters
None
Returns
table

1-based array of MeshInstance3D node wrappers.

Description

Returns all 3D mesh instances that compose this entity.

# getNodes METHOD
entity:getNodes([typeName], [recursive = true])
Returns all child nodes optionally filtered by class type.
Parameters
ParameterTypeDefaultDescription
typeNamestring""

Class type filter (e.g. "MeshInstance3D").

recursiveboolean`true`

Search all descendants.

Returns
table

1-based array of node wrappers.

Description

Searches the entity visual hierarchy for nodes matching the specified class type.

# getParent METHOD
entity:getParent()
Gets the parent entity.
Parameters
None
Returns
entity

Parent entity, or nil.

Description

Returns the parent entity containing or holding this entity.

# getParticleNodes METHOD
entity:getParticleNodes()
Gets all particle emitter nodes in the entity.
Parameters
None
Returns
table

1-based array of particle emitter nodes.

Description

Returns GPUParticles3D and CPUParticles3D nodes attached to the entity.

# getPartsByMaterial METHOD
entity:getPartsByMaterial(material)
Finds child mesh nodes that use the specified material.
Parameters
ParameterTypeDefaultDescription
materialstring|materialdef

Material ID or definition.

Returns
table

Array of matching node wrappers.

Description

Returns mesh nodes that render with material.

# getPartsByTexture METHOD
entity:getPartsByTexture(textureName)
Finds child mesh nodes that use the specified texture.
Parameters
ParameterTypeDefaultDescription
textureNamestring

Texture name.

Returns
table

Array of matching node wrappers.

Description

Returns mesh nodes that render with textureName.

# getRawAttributeF METHOD
entity:getRawAttributeF(attributeDef)
Gets the raw float attribute value without state buffs.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
number

Unmodified float attribute value.

Description

Returns the raw attribute value stored on the entity instance.

# getRawAttributeI METHOD
entity:getRawAttributeI(attributeDef)
Gets the raw integer attribute value without state buffs.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
number

Unmodified integer attribute value.

Description

Returns the raw integer attribute value.

# getRawAttributeS METHOD
entity:getRawAttributeS(attributeDef)
Gets the raw string attribute value.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
string

Unmodified string attribute value.

Description

Returns the raw string attribute value.

# getState METHOD
entity.getState(entity, stateDef)
Gets an active state wrapper on the entity.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity.

stateDefstring|statedef

State definition.

Returns
state

Active state wrapper, or invalid state wrapper if not present.

Description

Looks up the active status effect instance matching stateDef on the entity.

# getStates METHOD
entity.getStates(entity)
Returns all active states on the entity.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity.

Returns
table

1-based array of active state objects.

Description

Returns a table containing all currently applied status effects.

# getSurfacePosition METHOD
entity:getSurfacePosition()
Gets the terrain ground position beneath the entity.
Parameters
None
Returns
vector3

3D ground coordinates directly beneath entity.

Description

Calculates the terrain surface coordinate at the entity X and Z coordinates.

# getTextures METHOD
entity:getTextures()
Gets the names of all textures used across entity mesh surfaces.
Parameters
None
Returns
table

Array of texture name strings.

Description

Returns texture file names referenced by mesh materials.

# getWorldAabb METHOD
entity:getWorldAabb()
Gets the world-space bounding box of the entity.
Parameters
None
Returns
aabb

World-space bounding box.

Description

Shortcut for entity:getAabb(true).

# hasMaterial METHOD
entity:hasMaterial(material)
Checks if the entity uses a specific material.
Parameters
ParameterTypeDefaultDescription
materialstring|materialdef

Material ID or definition to check.

Returns
boolean

true if entity uses the material.

Description

Tests whether any mesh surface on the entity uses the specified material.

# hasState METHOD
entity.hasState(entity, stateDef)
Checks if an entity has a specific active state.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity.

stateDefstring|statedef

State definition.

Returns
boolean

true if entity currently has the state.

Description

Returns true if the state is currently applied.

# hasTexture METHOD
entity:hasTexture(textureName)
Checks if the entity uses a specific texture.
Parameters
ParameterTypeDefaultDescription
textureNamestring

Texture name to look for.

Returns
boolean

true if texture is used.

Description

Tests whether any surface uses textureName.

# isChildActive METHOD
entity:isChildActive(name, [recursive = true])
Checks if a child node is active.
Parameters
ParameterTypeDefaultDescription
namestring

Child node name.

recursiveboolean`true`

Search all descendants.

Returns
boolean

true if child node exists and is active.

Description

Returns true if the named child node is active in the scene hierarchy.

# remove METHOD
entity:remove()
Destroys and despawns the entity.
Parameters
None
Returns
boolean

true if removed successfully.

Description

Deletes the entity from the world and cleans up all scene nodes.

# removeAllStates METHOD
entity.removeAllStates(entity)
Removes all states from the entity.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity.

Returns
boolean

true if any states were removed.

Description

Clears all active status effects on the target entity.

# removeAttribute METHOD
entity:removeAttribute(attributeDef)
Removes an attribute override from the entity.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

Returns
boolean

true if attribute was present and removed.

Description

Removes the instance attribute override, resetting behavior to default definitions.

# removeState METHOD
entity.removeState(entity, stateDef, [invokeLua = true])
Removes a specific state from the entity.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity.

stateDefstring|statedef

State definition.

invokeLuaboolean`true`

Whether to fire onRemove hooks.

Returns
boolean

true if state was found and removed.

Description

Removes the status effect from the target entity.

# setAttributeF METHOD
entity:setAttributeF(attributeDef, value)
Sets a float attribute on the entity.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

valuenumber

Float value to assign.

Returns
None (void)
Description

Assigns a float attribute value (e.g. custom durability, health).

# setAttributeI METHOD
entity:setAttributeI(attributeDef, value)
Sets an integer attribute on the entity.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

valuenumber

Integer value to assign.

Returns
None (void)
Description

Assigns an integer attribute value.

# setAttributeS METHOD
entity:setAttributeS(attributeDef, value)
Sets a string attribute on the entity.
Parameters
ParameterTypeDefaultDescription
attributeDefattributedef

Attribute descriptor.

valuestring

String value to assign.

Returns
None (void)
Description

Assigns a string attribute value.

# setChildActive METHOD
entity:setChildActive(name, active, [recursive = true])
Enables or disables a child node by name.
Parameters
ParameterTypeDefaultDescription
namestring

Child node name.

activeboolean

Active state.

recursiveboolean`true`

Search all descendants.

Returns
boolean

true if node was found and updated.

Description

Toggles active processing and visibility for the named child node.

# setChildMeshVisible METHOD
entity.setChildMeshVisible(entity, name, visible, [recursive = true])
Toggles visibility of a named child mesh node.
Parameters
ParameterTypeDefaultDescription
entitynumber|entity

Target entity.

namestring

Child node name.

visibleboolean

Visibility state.

recursiveboolean`true`

Search descendants.

Returns
boolean

true if node was found and updated.

Description

Finds a child node by name and sets its active/visible state.

# setDefinition METHOD
entity:setDefinition(def)
Morphs the entity into a different definition.
Parameters
ParameterTypeDefaultDescription
defstring|entitydef

New definition ID or descriptor.

Returns
boolean

true if definition was morphed successfully.

Description

Dynamically changes the definition of an entity instance (e.g. growing a plant from stage 1 to stage 2).

e:setDefinition("apple_tree_grown")
# setParent METHOD
entity:setParent(parent, [isStoredOutside = false])
Attaches the entity to a parent entity.
Parameters
ParameterTypeDefaultDescription
parententity|number|nil

New parent entity or nil to unparent.

isStoredOutsideboolean`false`

Whether item remains visible outside.

Returns
boolean

true if reparenting succeeded.

Description

Reparents the entity to parent.

# spawn METHOD
entity.spawn(def, position, [scale])
Spawns an entity into the world.
Parameters
ParameterTypeDefaultDescription
defstring|entitydef

Entity definition ID or descriptor.

positionvector3

3D world spawn position.

scalevector3`(1, 1, 1)`

Scale vector.

Returns
entity

The spawned entity, or nil on failure.

Description

Spawns a new entity of definition def at the given 3D coordinates.

local stone = entity.spawn("stone", vector3.new(0, 10, 0))
# spawnOnGround METHOD
entity.spawnOnGround(def, position, [yRot = 0], [scale])
Spawns an entity aligned on the ground surface.
Parameters
ParameterTypeDefaultDescription
defstring|entitydef

Entity definition ID or descriptor.

positionvector3

Horizontal world position.

yRotnumber`0`

Yaw rotation in degrees.

scalevector3`(1, 1, 1)`

Scale vector.

Returns
entity

The spawned entity aligned with terrain ground.

Description

Calculates the ground height and slope at position and spawns the entity aligned to the terrain.

# store METHOD
entity.store(item, parent, [amount = -1], [capacityLimit = false])
Stores an item entity into a container entity.
Parameters
ParameterTypeDefaultDescription
itemnumber|entity

Item entity to store.

parentnumber|entity

Container or inventory parent entity.

amountnumber`-1`

Quantity to store (-1 for entire stack).

capacityLimitboolean`false`

Whether to enforce container weight/capacity limits.

Returns
boolean

true if stored successfully.

Description

Moves item into the inventory of parent.

# unparent METHOD
entity:unparent()
Detaches the entity from its current parent.
Parameters
None
Returns
boolean

true if detached successfully.

Description

Unparents the entity, placing it directly into the world root.

# onChangeChildren HOOK
entity:onChangeChildren(entityId)
Triggered when children are added, removed, or stack count changes.
Parameters
ParameterTypeDefaultDescription
entityIdnumber

Entity ID whose children changed.

Returns
None (void)
Description

Called whenever the child collection or stack sizes of this entity change.

# onChangeParent HOOK
entity:onChangeParent(entity, newParent, oldParent)
Triggered when the entity parent changes.
Parameters
ParameterTypeDefaultDescription
entityentity

The entity reparented.

newParententity|nil

New parent entity or nil.

oldParententity|nil

Old parent entity or nil.

Returns
None (void)
Description

Called when an entity is picked up into an inventory, transferred between containers, or dropped.

# onChangeStates HOOK
entity:onChangeStates(entityId)
Triggered when status effects are added or removed.
Parameters
ParameterTypeDefaultDescription
entityIdnumber

Entity ID whose states changed.

Returns
None (void)
Description

Called when the state list of the entity is modified.

# onCollect HOOK
entity:onCollect(parentId, entityId)
Triggered when an item entity is collected into an inventory.
Parameters
ParameterTypeDefaultDescription
parentIdnumber

Collector entity ID (e.g. player).

entityIdnumber

Collected item entity ID.

Returns
boolean

Return true to cancel collection.

Description

Called when picked up by a player or unit.

# onCollision HOOK
entity:onCollision(entity, other, speed)
Triggered on physical collision with another object or terrain.
Parameters
ParameterTypeDefaultDescription
entityentity

This entity.

otherentity|nil

The colliding entity, or nil if terrain/static.

speednumber

Impact velocity speed.

Returns
None (void)
Description

Called when an entity collides with another entity or surface.

# onConsume HOOK
entity:onConsume(consumer, entity)
Triggered when the entity is consumed (eaten or drunk).
Parameters
ParameterTypeDefaultDescription
consumerentity

The unit consuming the entity.

entityentity

The consumed item.

Returns
boolean

Return true if consumed successfully.

Description

Called when consuming food, medicine, or potions.

# onDamage HOOK
entity:onDamage(sourceId, targetId, weaponId, projectileIndex, hitPoint, damage, wasAlive)
Triggered during damage calculation.
Parameters
ParameterTypeDefaultDescription
sourceIdnumber

Attacking entity ID.

targetIdnumber

Damaged entity ID.

weaponIdnumber

Weapon entity ID.

projectileIndexnumber

Projectile index or 0.

hitPointvector3

3D hit point.

damagenumber

Calculated damage.

wasAliveboolean

Whether entity was alive before damage.

Returns
boolean

Return true to prevent damage from applying.

Description

Called when damage is about to be inflicted on the entity.

# onDestroy HOOK
entity:onDestroy(entity)
Triggered when the entity is destroyed.
Parameters
ParameterTypeDefaultDescription
entityentity

The entity being destroyed.

Returns
boolean

Return true to cancel destruction.

Description

Called when the entity is broken, depleted, or killed.

# onFocus HOOK
entity:onFocus(entityId)
Triggered when the player crosshair aims at the entity.
Parameters
ParameterTypeDefaultDescription
entityIdnumber

Entity ID being focused by player reticle.

Returns
string|number|table|void

Optional custom text or controls info to display on crosshair.

Description

Called when the HUD reticle points at this entity. Can return custom interaction prompt text.

# onHide HOOK
entity:onHide()
Triggered when the entity is hidden (e.g. chunk unloaded).
Parameters
None
Returns
None (void)
Description

Called when the entity is hidden or its chunk is unloaded.

# onHit HOOK
entity:onHit(sourceId, targetId, weaponId, projectileIndex)
Triggered when the entity is struck by an attack or tool.
Parameters
ParameterTypeDefaultDescription
sourceIdnumber

Entity ID of attacker / source.

targetIdnumber

Entity ID of target entity.

weaponIdnumber

Entity ID of weapon used, or 0.

projectileIndexnumber

Projectile index if hit by projectile, or 0.

Returns
boolean

Return true to cancel default hit handling and damage.

Description

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)
end
# onHourTick HOOK
entity:onHourTick(entityId)
Triggered every in-game hour for entities registered with hourly tick.
Parameters
ParameterTypeDefaultDescription
entityIdnumber

Entity ID.

Returns
None (void)
Description

Called on in-game hourly changes for plants, spoiled food, or time-dependent objects.

# onImpact HOOK
entity:onImpact(entityId, velocity, isOnFloor, airTime)
Triggered on movement impact / landing from height.
Parameters
ParameterTypeDefaultDescription
entityIdnumber

Entity ID.

velocityvector3

Landing velocity vector.

isOnFloorboolean

Whether landed on ground.

airTimenumber

Time in seconds spent airborne.

Returns
None (void)
Description

Called when a unit or object hits the ground after falling (e.g. for fall damage or landing sounds).

# onLiquidEnter HOOK
entity:onLiquidEnter(entity, liquidType)
Triggered when the entity enters water or liquid.
Parameters
ParameterTypeDefaultDescription
entityentity

This entity.

liquidTypenumber

Terrain liquid type enum (e.g. water, lava).

Returns
None (void)
Description

Called when entering a body of water or other terrain liquid.

# onLiquidLeave HOOK
entity:onLiquidLeave(entity)
Triggered when the entity leaves water or liquid.
Parameters
ParameterTypeDefaultDescription
entityentity

This entity.

Returns
None (void)
Description

Called when stepping or emerging out of liquid.

# onProjectileImpact HOOK
projectileDef:onProjectileImpact(spawnerId, targetId, weaponId, projectileIndex, position)
Triggered when a projectile strikes an entity or terrain.
Parameters
ParameterTypeDefaultDescription
spawnerIdnumber

Shooter unit ID.

targetIdnumber

Target entity ID, or 0 if hit terrain.

weaponIdnumber

Weapon entity ID.

projectileIndexnumber

Projectile index.

positionvector3

3D impact position.

Returns
boolean

Return true to prevent default projectile destruction.

Description

Declared on projectile entity definitions (e.g. arrows, thrown stones).

# onRandomSpawn HOOK
entity:onRandomSpawn(entity, position)
Triggered during procedural random map spawning.
Parameters
ParameterTypeDefaultDescription
entityentity

Newly created entity.

positionvector3

Spawn position.

Returns
None (void)
Description

Called when the entity is generated during procedural world generation or cluster spawning.

# onShow HOOK
entity:onShow()
Triggered when the entity becomes active and visible (e.g. chunk loaded).
Parameters
None
Returns
None (void)
Description

Called when the chunk containing the entity is loaded and the entity is shown.

# onSpawn HOOK
entity:onSpawn()
Triggered when the entity is freshly created and spawned into the world.
Parameters
None
Returns
None (void)
Description

Invoked immediately after the entity is spawned in the game world.

def.item.flare.onSpawn = function(self)
    print("Flare spawned: " .. self.id)
end
# onStateApply HOOK
entity:onStateApply(stateDefIndex, value, duration, stateValue, stateRemainingDuration)
Triggered when a status effect is successfully applied to the entity.
Parameters
ParameterTypeDefaultDescription
stateDefIndexnumber

Index of state definition.

valuenumber

Applied value.

durationnumber

Applied duration.

stateValuenumber

Current state value.

stateRemainingDurationnumber

Remaining duration.

Returns
None (void)
Description

Called immediately after a state is attached to the entity.

# onStateRemove HOOK
entity:onStateRemove(stateDefIndex, stateValue, stateRemainingDuration, isExpire)
Triggered when a status effect is removed or expires.
Parameters
ParameterTypeDefaultDescription
stateDefIndexnumber

Index of state definition.

stateValuenumber

State value.

stateRemainingDurationnumber

Remaining duration.

isExpireboolean

True if state expired naturally.

Returns
boolean

Return true to cancel state removal.

Description

Called before removing a state from the entity.

# onStateTick HOOK
entity:onStateTick(stateDefIndex, stateValue, stateDuration, stateRemainingDuration)
Periodic tick for states applied to the entity.
Parameters
ParameterTypeDefaultDescription
stateDefIndexnumber

Index of state definition.

stateValuenumber

Current intensity value.

stateDurationnumber

Total duration.

stateRemainingDurationnumber

Remaining duration in seconds.

Returns
None (void)
Description

Called every state tick interval (e.g. applying poison damage every second).

# onStateTryApply HOOK
entity:onStateTryApply(stateDefIndex, value, duration)
Entity-side check before applying a state.
Parameters
ParameterTypeDefaultDescription
stateDefIndexnumber

Index of state definition.

valuenumber

Proposed state value.

durationnumber

Proposed state duration.

Returns
boolean

Return true to prevent the state from being applied.

Description

Allows an entity to be immune or resist specific status effects.

# onUpdate HOOK
entity:onUpdate(entity, delta)
Periodic frame update hook for entities requiring active script ticking.
Parameters
ParameterTypeDefaultDescription
entityentity

This entity.

deltanumber

Elapsed time in seconds since last frame.

Returns
None (void)
Description

Invoked every frame for entities that declare onUpdate.

# onUse HOOK
entity:onUse(user, entity)
Triggered when the entity is used / interacted with.
Parameters
ParameterTypeDefaultDescription
userentity

The interacting player or unit.

entityentity

The entity being used.

Returns
boolean

Return true to cancel default use / inventory loot behavior.

Description

Called when the player presses the interaction key on this entity.

# onUseAlt HOOK
entity:onUseAlt(user, entity)
Triggered on secondary / alternate interaction.
Parameters
ParameterTypeDefaultDescription
userentity

Interacting unit.

entityentity

Target entity.

Returns
boolean

Return true if handled.

Description

Called when secondary interaction occurs (e.g. right click or alternate use binding).

# onUseDead HOOK
entity:onUseDead(userId, entityId)
Triggered when interacting with a dead unit.
Parameters
ParameterTypeDefaultDescription
userIdnumber

ID of the user.

entityIdnumber

ID of the dead entity.

Returns
boolean

Return true to cancel default looting.

Description

Called when looting a defeated animal or enemy.