API reference
API reference
Select your platform
No SDKs available
No versions available

Light Class

Extends ComponentBase
Modifiers: final
Dynamic light component for illuminating scenes with point or spot lights.
Lights are automatically managed by the LightSystem, which creates and updates native SceneLight instances based on the component data and entity Transform.
The system supports up to 4 lights per object for optimal performance on Quest devices. Lights are automatically prioritized based on distance and intensity, so the most important lights affect each object.
Example:
// Create a point light
Entity.create(listOf(
    Light(
        type = LightType.POINT,
        color = Vector3(1f, 0.9f, 0.8f),
        intensity = 2.0f,
        range = 10f
    ),
    Transform(Pose(Vector3(0f, 2f, 0f)))
))
// Create a spot light
Entity.create(listOf(
    Light(
        type = LightType.SPOT,
        color = Vector3(1f, 1f, 1f),
        intensity = 5.0f,
        range = 15f,
        direction = Vector3(0f, -1f, 0f),
        spotOuterAngle = 45f,
        spotInnerAngle = 30f
    ),
    Transform(Pose(Vector3(0f, 3f, 0f)))
))

Signature

class Light(type: LightType = LightType.POINT, color: Vector3 = Vector3(1.0f, 1.0f, 1.0f), intensity: Float = 1.0f, range: Float = 10.0f, direction: Vector3 = Vector3(0.0f, -1.0f, 0.0f), spotOuterAngle: Float = 45.0f, spotInnerAngle: Float = 30.0f, castsShadow: Boolean = false, enabled: Boolean = true) : ComponentBase

Constructors

Light ( type , color , intensity , range , direction , spotOuterAngle , spotInnerAngle , castsShadow , enabled )
Signature
constructor(type: LightType = LightType.POINT, color: Vector3 = Vector3(1.0f, 1.0f, 1.0f), intensity: Float = 1.0f, range: Float = 10.0f, direction: Vector3 = Vector3(0.0f, -1.0f, 0.0f), spotOuterAngle: Float = 45.0f, spotInnerAngle: Float = 30.0f, castsShadow: Boolean = false, enabled: Boolean = true)
Parameters
type: LightType  The type of light (Point or Spot)
color: Vector3  Light color in linear RGB. Each component should be in 0, 1 range
intensity: Float  Light intensity multiplier. Values greater than 1 create brighter lights
range: Float  Attenuation range in world units. Light contribution is zero beyond this distance
direction: Vector3  Direction for spot lights (will be normalized). Ignored for point lights
spotOuterAngle: Float  Spot light outer cone angle in degrees. Light falls off to zero at this angle
spotInnerAngle: Float  Spot light inner cone angle in degrees. Light is at full intensity within this angle
castsShadow: Boolean  Whether this light should cast shadows (requires shadow system to be enabled)
enabled: Boolean  Whether this light is currently active
Returns
Light

Properties

cachable : BuildConfig.COMPONENTCACHE_LEVEL >= 1
[Get][Set]
Signature
open override var cachable: BuildConfig.COMPONENTCACHE_LEVEL >= 1
castsShadow : Boolean
[Get][Set]
Whether this light should cast shadows
Signature
var castsShadow: Boolean
color : Vector3
[Get][Set]
Light color in linear RGB (not sRGB)
Signature
var color: Vector3
direction : Vector3
[Get][Set]
Direction for spot lights (normalized)
Signature
var direction: Vector3
enabled : Boolean
[Get][Set]
Whether this light is currently active
Signature
var enabled: Boolean
entID : Long
[Get][Set]
Signature
var entID: Long
intensity : Float
[Get][Set]
Light intensity multiplier
Signature
var intensity: Float
isDirty : Boolean
[Get][Set]
Signature
var isDirty: Boolean
range : Float
[Get][Set]
Attenuation range in world units
Signature
var range: Float
recycled : Boolean
[Get][Set]
Signature
var recycled: Boolean
spotInnerAngle : Float
[Get][Set]
Spot light inner cone angle in degrees
Signature
var spotInnerAngle: Float
spotOuterAngle : Float
[Get][Set]
Spot light outer cone angle in degrees
Signature
var spotOuterAngle: Float
timeStamp : Long
[Get][Set]
Signature
var timeStamp: Long
type : LightType
[Get][Set]
The type of light (Point or Spot)
Signature
var type: LightType

Methods

companion ()
Gets the companion object for this component.
The companion object provides metadata about the component.
Signature
open override fun companion(): ComponentCompanion
Returns
ComponentCompanion  The component's companion object
Throws
RuntimeException  If the companion is not implemented
getComponentDataAttributeType ( key )
Gets the attribute type for the specified key.
Signature
fun getComponentDataAttributeType(key: Int): AttributePrimitive?
Parameters
key: Int  The integer key to look up
Returns
AttributePrimitive?  The attribute primitive type, or null if the key doesn't exist
getComponentDataAttributeType ( keyString )
Gets the attribute type for the specified string key.
Signature
fun getComponentDataAttributeType(keyString: String): AttributePrimitive?
Parameters
keyString: String  The string key to look up
Returns
AttributePrimitive?  The attribute primitive type
Throws
IllegalArgumentException  If the key doesn't exist
getComponentDataKey ( key )
Gets the integer key associated with the specified string key.
Signature
fun getComponentDataKey(key: String): Int?
Parameters
key: String  The string key to look up
Returns
Int?  The integer key, or null if the string key doesn't exist
getComponentDataValue ( key )
Gets the value for the specified key.
Signature
fun getComponentDataValue(key: Int): Any?
Parameters
key: Int  The integer key to look up
Returns
Any?  The value associated with the key, or null if the key doesn't exist
getComponentDataValue ( keyString )
Gets the value for the specified string key.
Signature
fun getComponentDataValue(keyString: String): Any?
Parameters
keyString: String  The string key to look up
Returns
Any?  The value associated with the key, or null if the key doesn't exist
Throws
IllegalArgumentException  If the key doesn't exist
getEnumClass ( key )
Gets the enum class associated with the specified string key.
Signature
fun getEnumClass(key: String): Class<out Enum<*>>?
Parameters
key: String  The string key to look up
Returns
Class?  The enum class, or null if the key doesn't exist or is not an enum
hasAttributeChanges ()
Returns true if any attribute has been modified since the last read/write sync.
This is a read-only check. To clear the flag, call Entity.setComponent which syncs changes to native and resets the dirty state.
Signature
fun hasAttributeChanges(): Boolean
Returns
Boolean
hasComponentData ( key )
Checks if this component has data for the specified key.
Signature
fun hasComponentData(key: Int): Boolean
Parameters
key: Int  The integer key to check
Returns
Boolean  True if the component has data for the key, false otherwise
hasComponentData ( keyString )
Checks if this component has data for the specified string key.
Signature
fun hasComponentData(keyString: String): Boolean
Parameters
keyString: String  The string key to check
Returns
Boolean  True if the component has data for the key, false otherwise
read ( e , cachable )
Reads component data from the specified entity.
Signature
fun read(e: Entity, cachable: Boolean)
Parameters
e: Entity  The entity to read data from
cachable: Boolean  Whether the component's data should be cached
recycle ()
Recycles this component by returning it to its pool.
If the component has a pool assigned, it will be returned to that pool for reuse.
Signature
fun recycle()
reset ()
Resets the component to its default state.
This method is called when a component is recycled to clear any state. Subclasses should override this method to reset their specific state.
Signature
open fun reset()
setComponentDataValue ( key , value )
Sets the value for the specified key.
Signature
fun setComponentDataValue(key: Int, value: Any): Boolean
Parameters
key: Int  The integer key to set
value: Any  The value to set
Returns
Boolean  True if the value was set successfully, false otherwise
setComponentDataValue ( keyString , value )
Sets the value for the specified string key.
Signature
fun setComponentDataValue(keyString: String, value: Any): Boolean
Parameters
keyString: String  The string key to set
value: Any  The value to set
Returns
Boolean  True if the key exists and the value was set, false otherwise
setPool ( pool , entID )
Sets the component pool and entity ID for this component.
This is used for component recycling to track which pool the component belongs to and which entity it was associated with.
Signature
fun setPool(pool: ComponentPool<*>, entID: Long)
Parameters
pool: ComponentPool  The component pool this component belongs to
entID: Long  The ID of the entity this component is associated with
toString ()
Signature
open override fun toString(): String
Returns
String
typeID ()
Returns the unique type ID of this component.
Each component type must have a unique ID for identification in the entity-component system.
Signature
open override fun typeID(): Int
Returns
Int  The unique type ID for this component
write ( e )
Writes this component's data to the specified entity.
Signature
fun write(e: Entity)
Parameters
e: Entity  The entity to write this component's data to

Companion Object

Properties

attributeKeys_ : IntArray
[Get]
Signature
val attributeKeys_: IntArray
attributeTypeCounts_ : IntArray
[Get]
Signature
val attributeTypeCounts_: IntArray
attributeTypes_ : IntArray
[Get]
Signature
val attributeTypes_: IntArray
attrMetaData_ : Map
[Get]
Signature
val attrMetaData_: Map
castsShadowData : BooleanAttributeData
[Get]
Signature
val castsShadowData: BooleanAttributeData
castsShadowId :
[Get]
Signature
val castsShadowId: 
[Get]
Signature
val colorData: Vector3AttributeData
colorId :
[Get]
Signature
val colorId: 
createDefaultInstance : Function0
[Get]
Signature
open override val createDefaultInstance: () -> Light
directionData : Vector3AttributeData
[Get]
Signature
val directionData: Vector3AttributeData
directionId :
[Get]
Signature
val directionId: 
enabledData : BooleanAttributeData
[Get]
Signature
val enabledData: BooleanAttributeData
enabledId :
[Get]
Signature
val enabledId: 
enumClassesMap_ : Map
[Get]
Signature
val enumClassesMap_: Map<Int, Class<out Enum<*>>>
id :
[Get]
Signature
open override val id: 
intensityData : FloatAttributeData
[Get]
Signature
val intensityData: FloatAttributeData
intensityId :
[Get]
Signature
val intensityId: 
keyStringToKeyIntMap_ : Map
[Get]
Signature
val keyStringToKeyIntMap_: Map<String, Int>
rangeData : FloatAttributeData
[Get]
Signature
val rangeData: FloatAttributeData
rangeId :
[Get]
Signature
val rangeId: 
spotInnerAngleData : FloatAttributeData
[Get]
Signature
val spotInnerAngleData: FloatAttributeData
spotInnerAngleId :
[Get]
Signature
val spotInnerAngleId: 
spotOuterAngleData : FloatAttributeData
[Get]
Signature
val spotOuterAngleData: FloatAttributeData
spotOuterAngleId :
[Get]
Signature
val spotOuterAngleId: 
[Get]
Signature
val typeData: EnumAttributeData
typeId :
[Get]
Signature
val typeId: 

Methods

attributeKeys ()
Signature
open override fun attributeKeys(): IntArray
Returns
IntArray
attributeMetaData ()
Returns
Map
attributeTypeCountAvailable ()
Signature
open override fun attributeTypeCountAvailable(): Boolean
Returns
Boolean
attributeTypeCounts ()
Signature
open override fun attributeTypeCounts(): IntArray
Returns
IntArray
attributeTypes ()
Signature
open override fun attributeTypes(): IntArray
Returns
IntArray
dependents ()
Signature
open fun dependents(): IntArray
Returns
IntArray
enumClassesMap ()
Signature
open override fun enumClassesMap(): Map<Int, Class<out Enum<*>>>
Returns
Map
keyStringToKeyIntMap ( keyString )
Signature
open override fun keyStringToKeyIntMap(keyString: String): Int?
Parameters
keyString: String
Returns
Int?