-
Notifications
You must be signed in to change notification settings - Fork 5
Entity
Berke edited this page Jun 23, 2026
·
1 revision
The Entities type exposes a script-side wrapper around engine entities. It allows Lua scripts to query entity validity and safely access attached components.
All component accessors return nil if the component does not exist on the entity.
local id = entity.idReturns the internal entity ID.
numberlocal valid = entity.isValidReturns whether the entity is still valid in the scene.
booleanEach component follows the same pattern:
-
hasX→ checks if component exists -
x→ returns component ornil
local has = entity.hasTransformlocal t = entity.transformReturns the entity's transform component or nil.
Transform | nillocal has = entity.hasSpritelocal s = entity.spriteReturns sprite component or nil.
Sprite | nillocal has = entity.hasDecallocal d = entity.decalReturns decal component or nil.
local has = entity.hasAudioSourcelocal a = entity.audioSourceReturns audio source component or nil.
local has = entity.hasScriptlocal s = entity.scriptReturns script component or nil.
local has = entity.hasPlayerControllerlocal p = entity.playerControllerReturns player controller component or nil.
local has = entity.hasCameralocal c = entity.cameraReturns camera component or nil.
entity.hasCollider
entity.colliderentity.hasRigidbody
entity.rigidbodyentity.hasUITransform
entity.uiTransformentity.hasUISprite
entity.uiSpriteentity.hasUIText
entity.uiTextif entity.hasTransform then
local t = entity.transform
print(t.position.x)
end
if entity.hasCamera then
local cam = entity.camera
print("Camera active")
end
if entity.hasRigidbody then
entity.rigidbody:ApplyForce(Vector3(0, 10, 0))
end- All component access is safe (returns
nilif missing). - Always check
hasXbefore using a component in performance-critical code. - This wrapper is designed for scripting convenience, not raw ECS access.