What is the best way to make an audio manager?
Asked Answered
I

5

0

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?

Instauration answered 14/6, 2020 at 18:24 Comment(0)
V
0

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.

Viscountcy answered 14/6, 2020 at 21:38 Comment(0)
T
0

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.

Tisman answered 15/6, 2020 at 13:29 Comment(0)
P
0

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

Pronto answered 29/6, 2020 at 8:50 Comment(0)
P
0

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.

Pomposity answered 2/9, 2020 at 11:27 Comment(0)
P
0

Pronto I just want, one day, for all my scripts and code to be this clean and beautiful. You put the God in Godot. I creepy stare at your updates and issue merges. Thank you for all you do. You (and your Godot team) have allowed a simple ELA teacher the opportunity to gamify her curriculum and make it something middle schoolers want to learn. You are my Godro (that's Godot Hero).

Purpleness answered 20/3 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.