Search Unity

Audio Audio stops working after playing several sounds

Discussion in 'Audio & Video' started by BlackOpsBen, Apr 5, 2020.

  1. BlackOpsBen

    BlackOpsBen

    Joined:
    Jan 19, 2020
    Posts:
    5
    I have 6 guns in my scene, each with their own audiosource. Each gun produces it's own sound when fired.
    Whenever a bullet hits, a self-destructing prefab is instantiated which contains a particle effect and it's own audio source to play a hit sound. If I have all these guns shooting it's a matter of seconds before I lose all sound completely. What am I doing wrong? How do games have so many sounds yet I can only get a few going? Thanks for any help!
     
  2. JLF

    JLF

    Joined:
    Feb 25, 2013
    Posts:
    140
    It's possible you're running out of voices (the default is 32 I believe) but, what that wouldn't necessarily explain why you're losing all sounds all at once.

    My advice would be to check the detail tab in the Audio Profiler. This will show you how many sources and voices you have playing at a time and will show you if they are virtualised or can't play at all.

    That might shed a little more light as to what's going on. It might be that you've got a rogue script somewhere creating more Audio Sources than you thought.

    I wrote a whole article on audio optimisation on my blog: https://gamedevbeginner.com/unity-audio-optimisation-tips/ it explains how source culling and virtualisation works in Unity if that's any help.
     
    BlackOpsBen likes this.
  3. BlackOpsBen

    BlackOpsBen

    Joined:
    Jan 19, 2020
    Posts:
    5
    Thanks for your reply! I didn't know that. So in theory I should be able to have 32 sounds playing at once? I'll check and see what's happening.
     
    JLF likes this.