Skip to content

Light ​

Inherits: Node3D

LightEffect manages light sources and associated audio effects in the game world. It provides functionality to control both OmniLight3D and SpotLight3D nodes, as well as an associated AudioStreamPlayer3D for ambient sound effects.

Description ​

Key features:

  • Controls both OmniLight3D and SpotLight3D nodes
  • Manages an associated audio stream for ambient effects
  • Provides functionality to toggle shadows for performance optimization
  • Can be enabled/disabled for interactive lighting systems
  • Automatically adds itself to the "lights" group when entering the scene tree

Note: All instances of this class are automatically added to the "lights" group for proper scene organization and potential performance optimizations.

Properties ​

Light3Domni_light
SpotLight3Dspot_light
AudioStreamPlayer3Daudio_stream_player_3d
boollight_enabledtrue
boolshadows_enabledtrue
boolloop_audiotrue

Variables ​

floatstored_omni_energy1.0
floatstored_spot_energy1.0
boolstored_omni_visibletrue
boolstored_spot_visibletrue

Methods ​

voidstart_audio()
voidstop_audio()
voidset_audio_volume( volume: float )
voidtoggle_shadows( value: bool )
voidenable_shadows()
voiddisable_shadows()
voidset_light_enabled( enabled: bool )
voidenable_light()
voiddisable_light()
voidtoggle_light()
voidset_light_energy( energy: float )
voidset_light_color( color: Color )
voidset_omni_range( range_value: float )
voidset_spot_range( range_value: float )
voidset_spot_angle( angle_degrees: float )
voidanimate_light_energy( target_energy: float, duration: float = 1.0 )
voidanimate_light_color( target_color: Color, duration: float = 1.0 )
voidstart_flicker_effect( min_energy: float = 0.5, max_energy: float = 1.5, interval: float = 0.1 )
voidstop_flicker_effect()
boolis_light_enabled()
boolare_shadows_enabled()
boolhas_lights()
boolhas_audio()

Signals ​

light_turned_on() ​

Signal emitted when the light is turned on

light_turned_off() ​

Signal emitted when the light is turned off

shadows_toggled( enabled: bool ) ​

Signal emitted when shadows are toggled

Property descriptions ​

Light3D omni_light ​

Reference to the OmniLight3D node (if present)

SpotLight3D spot_light ​

Reference to the SpotLight3D node (if present)

AudioStreamPlayer3D audio_stream_player_3d ​

Reference to the AudioStreamPlayer3D for ambient sound effects

bool light_enabled = true ​

Whether the light is currently enabled

bool shadows_enabled = true ​

Whether shadows are enabled

bool loop_audio = true ​

Whether audio should loop continuously

Variable descriptions ​

float stored_omni_energy = 1.0 ​

The energy of the omni light, kept while it is switched off.

float stored_spot_energy = 1.0 ​

The energy of the spot light, kept while it is switched off.

bool stored_omni_visible = true ​

Whether the omni light was visible, kept while it is switched off.

bool stored_spot_visible = true ​

Whether the spot light was visible, kept while it is switched off.

Method descriptions ​

void start_audio() ​

Start playing the ambient audio

void stop_audio() ​

Stop playing the ambient audio

void set_audio_volume( volume: float ) ​

Set the audio volume (0.0 to 1.0)

void toggle_shadows( value: bool ) ​

Toggles shadow casting for both OmniLight3D and SpotLight3D (if present) This can be used for performance optimization by disabling shadows when not needed

void enable_shadows() ​

Enable shadows for all lights

void disable_shadows() ​

Disable shadows for all lights

void set_light_enabled( enabled: bool ) ​

Enable or disable the light effect

void enable_light() ​

Turn on the light effect

void disable_light() ​

Turn off the light effect

void toggle_light() ​

Toggle the light on/off

void set_light_energy( energy: float ) ​

Set the energy/brightness of all lights

void set_light_color( color: Color ) ​

Set the color of all lights

void set_omni_range( range_value: float ) ​

Set the range of omni light (if present)

void set_spot_range( range_value: float ) ​

Set the range of spot light (if present)

void set_spot_angle( angle_degrees: float ) ​

Set the spot light angle (if present)

void animate_light_energy( target_energy: float, duration: float = 1.0 ) ​

Animate light energy over time

void animate_light_color( target_color: Color, duration: float = 1.0 ) ​

Animate light color over time

void start_flicker_effect( min_energy: float = 0.5, max_energy: float = 1.5, interval: float = 0.1 ) ​

Flicker effect - randomly varies light energy

void stop_flicker_effect() ​

Stop flicker effect

bool is_light_enabled() ​

Check if the light is currently enabled

bool are_shadows_enabled() ​

Check if shadows are currently enabled

bool has_lights() ​

Check if any light components are present

bool has_audio() ​

Check if audio component is present