I’m making a game that will have tons of enemies in one scene and each of them has their own Audio Source and Clips.
My issue is, when they all start to stack around me and shoots me, the audio lags so much. The background music is cutting off, my shooting sfx is cutting off, explosion sfx is cutting off, etc…
Basically what’s going on is that there’s like 50+ audios playing at the same time and the sound breaks :/.
I’m using the PlayOneShot function on everything, btw.
What’s the best way to handle game audio in terms of having multiple audio sources and clips at the same time?
What file format are your sfx? If they’re ogg or mp3 there will be a lot of decompression going which is CUP intensive. You could also check your max voice count in the audio settings + the priority settings of the individual Audio Sources.
I went and checked my Audio Settings and I have 1024 on virtual voice count and 128 on real voice count.
What does that mean? (I’m new to audio stuffs)
I’ve also thought about the priority settings, yeah.
I only have 2 sound effects at the moment and that’s shooting sfx and explosion sfx. Shooting is at #2 priority and Explosion it at #1 priority. But again, the issue is when 30 enemies are shooting at the same time, all the shooting sfx stay at the same priority.
You don’t want to have 30 of them shooting at the same time, that can be super loud and performance-draining. You’ll need to make centralized code to handle that.
That’s the initial reason we created Master Audio, before it evolved into a more fully-featured audio plugin.
Yeah… I figured that it’s a very bad game-development practice…
Master Audio is something that I can’t afford at the moment.
Is there anywhere I could read or learn about how to do the “You’ll need to make centralized code to handle that.” or a general guide on coding efficiently with audio?
Basically we don’t put Audio Sources “on” any game objects like players, enemies, weapons, etc. Instead all Audio Sources are all located under a central MasterAudio game object by name of audio clip. Then there is code keeping track of how many of each are playing (so you can limit them to say 5) and it moves the Transform of that sub game object to the location of the object that’s supposed to be making the sound. By keeping the audio on a separate game object you also defeat the problem of making a death sound that gets cut off when the enemy gets destroyed.
If keeping track of how many is too complicated (it can be), instead just look at all the child game objects and see how many are playing each time.
As far as reading about how to do it, nowhere that I know of. I just figured out stuff as we went along and run into limitation after limitation.
I’m not a programmer so not sure how one go about this but as already said a drastic limit in audio sources is a good start. Our brains can’t percieve too many real-life inputs so a limit of just a couple of sources would still serve its purpose.
Next time you’re in a crowded place - like in a mall or busy street. How many distinct conversations or even footsteps can you make out? We don’t register much individual sounds as much as the collective sounds in a setting so just a few sources would be fine.
What about 2-3 weapon sources and an extra layer of more intense music?