Hi there, so I’ve noticed I have my gun shooting at a rate of once every 0.1s and it calls AudioSource.PlayOneShot() to play the gun shot sound.
However, what’s weird is when I hold down the shooting method, which calls AudioSource.PlayOneShot() every 0.1s, it sometimes stops doing the audio clip?
Anybody else notice this? What methods should I be using to call so fast such as every 0.1s and have it always play the sound properly?
Wow I have never even heard of these “voice limits” in unity, that’s crazy haha
These audio clips are only 1s long (at the maximum), since they are just gun shots, its a very quick 1s clip, however, if me and my friends are shooting at the same time it happens almost everytime. That makes sense because if the default is 32, then all it takes is 32 shots between us both to hit that limit.
How can I get around this then? Because obviously I need it to make the audio sound every gun shot (other wise its a really bad player-responsiveness haha)
Do I just need to simply change these values in the Audio Preferences?
What issues can arrise from me raising these values? (if any)
And also, what is the PlayOneShot method: is it “real” or “virtual”?
As far as I understand it, every Play One Shot is a real voice. Real voices are sounds you can actually hear, while virtual voices keep sounds that can’t be played (because of a real voice limit) running in the background so that they are playing back correctly once a real voice is available.
You can increase the voice limit up to 255, but try to aim for much lower than that depending on the target hardware. I couldn’t find published hardware limits for my article but around 40 would be a safe bet with up to 80 being on the higher end. The main issue you’d have is a hardware limit say, on console, or a phone, where it’s just not as high as you’ve set it.
To reduce the impact of the firing I would either reduce the length of the clip or limit it manually somehow, stopping the audio source playback every nth shot for example might work. Or use multiple audio sources with Play() and toggle between them. There’s going to be a more elegant way to do it but those are the basic approaches.
I’d probably try it with a looping clip instead, and then fade it out quickly when the firing stops.