Hello, how should I handle music and SFX in a complex game? I think to create audioManager with one AudioPlayer and manipulate in via script to play music but what with sound effects, how should I handle it? And should I preload all music and sfx in one place and call it via keys like play_sfx("Walk") or in other way?
Music and SFX in complex game
- Edited
Hello, how should I handle music and SFX in a complex game? I think to create audioManager with one AudioPlayer and manipulate in via script to play music but what with sound effects
To manage sound polyphony, I recommend using an autoload like this one.
Then call the autoload's functions to play sounds within your nodes. This lets a single node play multiple sounds at the same time and also ensures sounds play in full if the node itself is freed before the sound is done playing.
For music playback, you can use another autoload so that music playback continues if you change scenes using SceneTree.change_scene()
.
And should I preload all music and sfx in one place and call it via keys like play_sfx("Walk") or in other way?
You don't need to preload music and sound effects in one place, as Godot's preload()
function will handle that for you.
@Calinou Can I infer then that in 3D I'll be trying to use a single audio player, or multiple for each sound position?
That code looks like it would work for 3D if you just change the 2D to 3D.
ah I see because he took in a parent node it would be easy to get the 3d translation or location for the sound if needed.
Yes, the sound would take the position of the parent node automatically so should just work.