Skip to content

AudioComponent

AudioComponent

enable property writable

enable: bool

Whether this component is active. Disabling unloads every track's sound.

listener property writable

listener: bool

Whether this component is the scene's active audio listener. Setting this to True unsets listener on any other AudioComponent in the scene.

owner property

owner: Object

The Object that owns this component

add_child

add_child(obj: Object) -> Object

Add obj as a child of this component's owning Object

add_component

add_component(component_class: Any) -> typing.Any

Attach a new component of the given type to this component's owning Object.

Example
render = self.add_component(RenderComponent)

add_object

add_object(obj: Object, parent: Object = None) -> Object

Add a newly created Object to the scene, optionally parented to another Object

add_track

add_track(name: str = '', path: str = '', streaming: bool = False, loop: bool = False, volume: SupportsFloat | SupportsIndex = 1.0) -> str

Add a new audio track and return its actual name. If name collides with an existing track, a numeric suffix is appended to keep it unique, so check the returned value rather than assuming it matches what you passed in.

Example
track = audio.add_track('Footstep', 'res://sfx/step.wav')
audio.play(track)

get_audio_path

get_audio_path(name: str) -> str

res:// path to the track's audio file

get_component

get_component(component_class: Any) -> typing.Any

Look up a component on this Object

get_is_playing

get_is_playing(name: str) -> bool

Whether the given track is currently playing

get_loop

get_loop(name: str) -> bool

Whether the given track loops when it reaches the end

get_owner

get_owner() -> Object

The Object that owns this component

get_streaming

get_streaming(name: str) -> bool

Whether the given track streams from disk rather than being fully decoded into memory

get_track_names

get_track_names() -> list[str]

Names of every audio track on this component

get_volume

get_volume(name: str) -> float

Playback volume of the given track

has_component

has_component(component_class: Any) -> bool

Check whether this component's owning Object has a component of the given type

pause

pause(name: str) -> None

Pause playback of the track with the given name

play

play(name: str) -> None

Start (or resume) playback of the track with the given name.

Example
audio.play('Footstep')

remove_component

remove_component(component_class: Any) -> None

Remove a component of the given type from this component's owning Object

remove_object

remove_object(obj: Object) -> None

Remove an object from the scene

remove_track

remove_track(name: str) -> None

Remove the track with the given name

set_audio_path

set_audio_path(name: str, path: str) -> None

Set the audio file (a res:// path) for the given track. (Re)loads the sound immediately using its current streaming/loop settings.

set_enable

set_enable(enable: bool) -> None

Set enable. See the enable property.

set_listener

set_listener(listener: bool) -> None

Set listener. See the listener property.

set_loop

set_loop(name: str, loop: bool) -> None

Set loop for the given track. Reloads the sound if a path is set.

set_streaming

set_streaming(name: str, streaming: bool) -> None

Set streaming for the given track. Reloads the sound if a path is set.

set_volume

set_volume(name: str, volume: SupportsFloat | SupportsIndex) -> None

Set volume for the given track. Only takes effect once the track's sound is loaded.

stop

stop(name: str) -> None

Stop playback of the track with the given name