What is the best way to make an audio manager?

SebSharperSebSharper Posts: 4Member

Hi. So I have multiple audios for my player and some other entities. The problem is that when one audio is being played and I want another audio to play with the same AudioStreamPlayer2D, it stops playing the first audio and plays the second one. I have seen that I need an audio manager to fix this behaviour. What is the best way to achieve this? A dynamic audio manager? Should it be an auto-load script?

Tags :


  • bitshift-rbitshift-r Posts: 67Member

    I've seen the recommendation more than once to use multiple AudioStreamPlayer nodes (one for each sound effect) rather than making a manager. However the official 3d fps tutorial has a section on setting up a global audio player here.

  • TwistedTwiglegTwistedTwigleg Posts: 3,093Admin

    Either method, making a global audio player or creating audio streams for each sound effect, should work fine.

    The only, minor snag with creating audio streams for each sound effect is that, depending on how you pass the sound effect file, Godot may need to load the audio from a file prior to playing the sound effect. This could possibly create a slight delay/lag as Godot loads the file from the disk, however I have not seen this myself, but it could be something to consider. Using an audio manager can work around this by loading all the needed sound effects at the start, but that’s about the only advantage, outside of just general preference.

  • CalinouCalinou Posts: 464Admin Godot Developer

    See this script for an example of a Sound singleton that adds new instances on demand.

  • TheMnkTheMnk Posts: 47Member

    I built myself a "retro" system for audio reproduction.

    There are only 3 channels for sound (3 audiostream nodes) and 1 for music (1 audiostream node).
    So no more than 3 effects can be played at the same time.
    Sounds have a priority.
    If you have the 3 channels busy reproducing sounds of the environment with the lowest priority and you need to reproduce a shot with the highest priority, the system will check which channel is the most suitable and will select it immediately (because the sound of the gun has the highest priority) by stopping the sound that the channel was previously playing.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file