Does AudioStreamPlayer only worked when attached somewhere in the scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BlaXun

Hello everybody,
I am new to Godot and am struggling with soundeffect playback.
I am aware that a AudioStreamPlayer can only play a single sound at a time.

I came up with a script object that pre-loads 3 AudioStreamPlayer and tries to reuse them by checking if there is a AudioStreamPlayer that is currently not playing a sound, if there is no such player a new one is created.

When debugging everything looks fine. A player is found, the sound does exist, the play()-function does not crash… but there is no sound.

My assumption is that the AudioStreamPlayer does not play any sounds as long as it is not attached to any scene in the current room… so, maybe I have to attach the AudioStreamPlayers to the object that actually should play the sound?

I bet there is a pretty simple answer to this.
Thx in advance :slight_smile:

:bust_in_silhouette: Reply From: Calinou

Like nearly any node in Godot, AudioStreamPlayer needs to be added to the scene tree to have an effect.

PS: You can use an autoload like this one to create AudioStreamPlayer nodes from anywhere that are freed automatically when the sound is done playing.