component
The component namespace — the engine's Luau API reference for component.
The component namespace — 7 functions.
component/lifecycle/README
Component lifecycle hooks
Functions you can define in a component script. All are optional.
| Hook | When | Use |
|---|---|---|
| awake() | Once, when added | Init state, set up bridges |
| start() | Once, after all awake | Cross-component setup |
| update(dt) | Every frame | Movement, logic, animation |
| fixedUpdate(dt) | Physics rate | Force application |
| onPropertyChanged(key, val, old) | Public prop written externally | React to config changes |
| onEnable() / onDisable() | Toggled | Pause/resume |
| onDestroy() | Removed | Cleanup |
| onError(error) | Error occurs | Error indicators, recovery |
component/public/README
public — Component public properties
Declared with declare {} at the top of a component script. Public properties are visible to other scripts and the editor. Changes trigger onPropertyChanged().
Example:
declare {
speed = 5.0,
label = "Hello",
visible = true,
}
function update(dt)
-- public.speed is readable/writable from outside
local p = self.entity.position
self.entity.position = { p.x, p.y + public.speed * dt, p.z }
end
Read from outside: entity(id).component.get("MyComp").speed Write from outside: entity(id).component.get("MyComp").speed = 10
component/self/README
self — Component instance context
Available inside any component script. Provides access to the entity, instance ID, and init data.
Fields:
- self.entity — entity proxy (same as entity(self.entityId)). Access position, rotation, scale, components.
- self.entityId — string ID of the entity this component is attached to
- self.instanceId — unique string ID for this component instance
- self.data — the initial data table passed to entity.component.add()
- self.errors() — get error list for this component instance
Example:
function update(dt)
local p = self.entity.position
self.entity.position = { p.x, p.y + dt, p.z }
end
component/self/data
self.data -> table | nil
The initial data table passed as the second argument to entity.component.add(type, data). Available in awake() and all lifecycle hooks.
component/self/entity
self.entity -> EntityProxy
Entity proxy for the entity this component is on. Shorthand for entity(self.entityId). Use it to read/write position, rotation, scale, and manage other components.
Properties (read components, assign vectors):
- self.entity.position.x/.y/.z (read) ; self.entity.position = { x, y, z } (write) ; self.entity.position.x = n (one axis)
- self.entity.rotation.x/.y/.z/.w or .eulerAngles (read) ; self.entity.rotation = { qx,qy,qz,qw } or .eulerAngles = { pitch,yaw,roll } (write) ; .rotation.rotateAxisAngle(ax,ay,az,radians)
- self.entity.localScale.x/.y/.z (read) ; self.entity.localScale = { x, y, z } (write)
- self.entity.component.add(type, data?) / .remove(type) / .has(type) / .get(type) / .getAll()
- self.entity.name() -> string
- self.entity.id() -> string
- self.entity.setParent(parentId) / .unparent()
component/self/entityId
self.entityId -> string
The entity ID string for the entity this component is attached to. Use with entity() to get a proxy, or pass to API functions that take an entity ID.
component/self/instanceId
self.instanceId -> string
Unique identifier for this specific component instance. Useful for generating unique screen names, mesh IDs, etc.