Skip to content
Berke edited this page Jun 23, 2026 · 1 revision

Lua Entity Bindings

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.


Entity Core

id

local id = entity.id

Returns the internal entity ID.

Returns

number

isValid

local valid = entity.isValid

Returns whether the entity is still valid in the scene.

Returns

boolean

Components

Each component follows the same pattern:

  • hasX → checks if component exists
  • x → returns component or nil

Transform

hasTransform

local has = entity.hasTransform

transform

local t = entity.transform

Returns the entity's transform component or nil.

Returns

Transform | nil

Sprite

hasSprite

local has = entity.hasSprite

sprite

local s = entity.sprite

Returns sprite component or nil.

Returns

Sprite | nil

Decal

hasDecal

local has = entity.hasDecal

decal

local d = entity.decal

Returns decal component or nil.


Audio Source

hasAudioSource

local has = entity.hasAudioSource

audioSource

local a = entity.audioSource

Returns audio source component or nil.


Script

hasScript

local has = entity.hasScript

script

local s = entity.script

Returns script component or nil.


Player Controller

hasPlayerController

local has = entity.hasPlayerController

playerController

local p = entity.playerController

Returns player controller component or nil.


Camera

hasCamera

local has = entity.hasCamera

camera

local c = entity.camera

Returns camera component or nil.


Physics

Collider

entity.hasCollider
entity.collider

Rigidbody

entity.hasRigidbody
entity.rigidbody

UI Components

UI Transform

entity.hasUITransform
entity.uiTransform

UI Sprite

entity.hasUISprite
entity.uiSprite

UI Text

entity.hasUIText
entity.uiText

Example Usage

if 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

Notes

  • All component access is safe (returns nil if missing).
  • Always check hasX before using a component in performance-critical code.
  • This wrapper is designed for scripting convenience, not raw ECS access.

Clone this wiki locally