AudioComponent ​
Inherits: Node3D
AudioComponent - Unified audio playback system for entities and interactables Handles motion sounds, entity voice sounds, voicelines, and effect sounds using AudioManager's pooled system.
Description ​
This component creates RemoteTransform3D nodes to position audio in 3D space, then borrows AudioStreamPlayer3D instances from AudioManager's pools.
Features:
- Motion audio (footsteps) - uses SFX bus
- Entity voice audio (combat barks: attack, hit, pain) - uses Voice bus, requires entity setup
- Voiceline audio (dialogue) - uses Voice bus, works with any character name, single player tracked
- Effect audio (impacts, spells, etc.) - uses SFX bus
- Automatic cleanup and return of audio players
- Support for exclusive playback and fade effects
Variables ​
Array[RemoteTransform3D] | motion_remotes | [] |
Array[RemoteTransform3D] | voice_remotes | [] |
Array[RemoteTransform3D] | effect_remotes | [] |
RemoteTransform3D | voiceline_remote | null |
AudioStreamPlayer3D | active_voiceline_player | null |
Dictionary | active_players | {} # player -> {remote: RemoteTransform3D, requester_id:... |
Dictionary | active_exclusive_effects | {} # sound_path -> player |
String | entity_type | "" |
String | voice_type | "" |
bool | hit_audio_on_cooldown | false |
AudioManager | audio_manager | |
ChronoManager | chrono_manager |
Methods ​
void | setup_for_entity( owning_entity: Entity ) |
void | setup_for_interactable() |
bool | play_motion_audio( surface: String, movement: String ) |
bool | play_entity_voice_audio( action: String, volume: float = -5.0, pitch: float = 1.0 ) |
bool | play_voice_call( call_name: String, volume: float = -10.0, pitch: float = 1.0, ability: bool = false ) |
String | resolve_voice_call( call_name: String ) |
bool | play_voiceline_audio( character_name: String, file_name: String = "", volume: float = -5.0, speaker_name: String = "" ) |
void | stop_voice_line_audio() |
bool | play_hit_voice() |
bool | play_hit_long_voice() |
bool | play_hit_reaction_voice( heavy: bool ) |
bool | play_pain_voice() |
bool | play_death_voice() |
bool | play_trigger_voice( record: TriggerRecord ) |
bool | play_aggro_voice() |
bool | play_jump_start_voice() |
bool | play_jump_end_voice() |
bool | play_sound_stream( stream: AudioStream, volume_db: float = 0.0 ) |
bool | play_effect( sound: AudioStream, exclusive: bool = false, volume_db: float = 0.0, pitch_scale: float = 1.0, max_distance: float = 20.0, unit_size: float = 10.0 ) |
bool | play_sfx_selection( sfx_selection: SFXSelection, volume_modifier: float = 0.0 ) |
bool | stop_effect( sound: AudioStream ) |
void | stop_all_audio() |
Constants ​
intMOTION_REMOTE_COUNT =4 # For footsteps (left/right foot)- Number of RemoteTransform3D nodes to create for different audio typesintVOICE_REMOTE_COUNT =4- For voice lines and combat soundsintEFFECT_REMOTE_COUNT =4- For various effects
Variable descriptions ​
Array[RemoteTransform3D] motion_remotes = [] ​
The remote transforms the footstep sounds play from.
Array[RemoteTransform3D] voice_remotes = [] ​
The remote transforms the voice sounds play from.
Array[RemoteTransform3D] effect_remotes = [] ​
The remote transforms the effect sounds play from.
RemoteTransform3D voiceline_remote = null ​
Dedicated voiceline remote and tracking
AudioStreamPlayer3D active_voiceline_player = null ​
The player of the voice line that plays now.
Dictionary active_players = # player -> remote: RemoteTransform3D, requester_id: Strin ​
Track which audio players are currently in use
Dictionary active_exclusive_effects = # sound_path -> player ​
Track exclusive effect sounds to prevent duplicates
String entity_type = "" ​
The kind of entity, for its footsteps (humanoid ...).
String voice_type = "" ​
The voice of the entity.
bool hit_audio_on_cooldown = false ​
True while the hit sound waits before it can play again.
AudioManager audio_manager ​
SystemManager refs
ChronoManager chrono_manager ​
The manager of timers.
Method descriptions ​
void setup_for_entity( owning_entity: Entity ) ​
Setup for Entity usage - configures entity-specific audio properties
void setup_for_interactable() ​
Setup for Interactable usage - no entity-specific configuration needed
bool play_motion_audio( surface: String, movement: String ) ​
Play a motion sound (footsteps, etc.) - Entity only
bool play_entity_voice_audio( action: String, volume: float = -5.0, pitch: float = 1.0 ) ​
Play an entity voice sound (combat barks: attack, hit, pain, etc.) Requires entity_type and voice_type to be set via setup_for_entity()
bool play_voice_call( call_name: String, volume: float = -10.0, pitch: float = 1.0, ability: bool = false ) ​
Plays a voice call by its name (see VoiceCalls): the call, its older names and the calls it falls back to, the first one the voice has files for. A voice that has none of them is silent (no warning: a voice without a dodge sound is allowed; the Entity Voices editor lists what is missing). ability true: a voice sound of an ability, whose name no voice need have, warns when nothing is found
String resolve_voice_call( call_name: String ) ​
The folder of the voice that a call plays: the call, its older name or the call it falls back to, whichever the voice has files for first. "" when the voice has none of them
bool play_voiceline_audio( character_name: String, file_name: String = "", volume: float = -5.0, speaker_name: String = "" ) ​
Play a voiceline (dialogue) for a specific character Can get random voiceline or specific file by name Only one voiceline can play at a time - automatically stops previous voiceline
void stop_voice_line_audio() ​
Stop all voice line audio from this component
bool play_hit_voice() ​
Play a hit sound with cooldown
bool play_hit_long_voice() ​
Play a heavy hit sound with cooldown (a voice without one uses the hit sound)
bool play_hit_reaction_voice( heavy: bool ) ​
The sound of being hit: the heavy one for a hit that takes a quarter of the health at once, else the light one. One a second at most
bool play_pain_voice() ​
Play a pain sound with cooldown
bool play_death_voice() ​
The sound of dying (a voice without one uses Pain, then Hit)
bool play_trigger_voice( record: TriggerRecord ) ​
The voice call of a trigger that fired on the entity (a dodge, a parry, a block, a critical strike ... any trigger with "Has a voice call"): the call is named by its slot, a voice without it uses the call the trigger falls back to. One every half second per trigger at most
bool play_aggro_voice() ​
The sound of starting a fight (one every eight seconds at most)
bool play_jump_start_voice() ​
Play a jump start voice
bool play_jump_end_voice() ​
Play a jump end voice
bool play_sound_stream( stream: AudioStream, volume_db: float = 0.0 ) ​
Plays a sound stream where this object is (doors and containers use this name)
bool play_effect( sound: AudioStream, exclusive: bool = false, volume_db: float = 0.0, pitch_scale: float = 1.0, max_distance: float = 20.0, unit_size: float = 10.0 ) ​
Play an effect sound with various options
bool play_sfx_selection( sfx_selection: SFXSelection, volume_modifier: float = 0.0 ) ​
Play an SFX selection (for interactables)
bool stop_effect( sound: AudioStream ) ​
Stop a specific effect sound
void stop_all_audio() ​
Stop all audio from this component