Search Unity

Audio Setting the volume of my audiosource to 0 does not mute it.

Discussion in 'Audio & Video' started by DuraniRobben, Jul 7, 2018.

  1. DuraniRobben

    DuraniRobben

    Joined:
    Apr 23, 2018
    Posts:
    3
    Hey everyone, first time posting here, so please forgive me.

    I attached an audiofile to my main camera. The audio is set on PlayOnAwake so that all works fine.
    While implementing an audioslider in my menu I found out that I couldnt mute the audio. Neither with the mute button, nor with setting the volume to 0. Changing the volume does infact change the volume, but only between loud and very loud.

    Thanks in advance! Any help/ideas are appreciated.
     
  2. Docaroo

    Docaroo

    Joined:
    Nov 7, 2017
    Posts:
    82
    Double check that you don't have a duplicate of that audiosource playing alongside the one you are editing. Also check it's not enabled for 3D sound... Volume 0 should still mute the audio even with 3d sound but it's worth ruling out!
     
    PeterMacak and tubelightboy like this.
  3. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    @Docaroo has probably already found the problem.

    However you should keep in mind that muting an AudioSource using only the volume not actually save you any performance!

    The ".mute" property will internally also exempt the AudioSource from mixing, thus saving you performance.
    Setting the volume to 0 however will not.

    An AudioSource with volume=0 will internally still play, and cause the audio system to still include it in the mixing calculations, even though all the samples it outputs will be multiplied by zero.

    That will become a drain on performance rather quickly. So if you have some stuff where the volume is controlled by some user setting (like "sfx volume" in many games) make sure to use the mute property.
     
  4. Docaroo

    Docaroo

    Joined:
    Nov 7, 2017
    Posts:
    82
    Are you sure that is also the case in builds? In the testing I've done even a "muted" audiosource keeps the mixers active and runs through any effects ... it looks like it has the same impact as a volume=0 source.

    Although, when it comes to building the project these things are all optimized so I wonder how muting and volume=0 translates into the build?
     
  5. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    Yes it is the case also in builds, but it might not be noticeable until there are rather high numbers of audiosources
    You should see impact on this reflected in e.g. DSP CPU % in the profiler
     
  6. DuraniRobben

    DuraniRobben

    Joined:
    Apr 23, 2018
    Posts:
    3
    I might not have been clear.

    I have a script that lowers the volume of the music after clicking a button. And that works just fine. After 1 second (since I made it so) the sound is muted (and the song is stopped so that it wont play silently).
    However I linked the audiosource to a slider. Changing that slider does nothing. And even after selecting the Audiosource and changing the slider provided by Unity in the Inspector only changes the volume from loud to less loud, but not from loud to muted.

    Oh my god!

    as @Docaroo said, I had another AudioSource playing.
    thanks for making me check=) it works now=)
     
    Last edited: Jul 11, 2018
  7. Docaroo

    Docaroo

    Joined:
    Nov 7, 2017
    Posts:
    82
    Haha that was a bit of a hail mary call that one but just goes to show it's always worth checking absolutely everything just in case!

    Glad you solved it!
     
  8. gamedevelopmenttsunami

    gamedevelopmenttsunami

    Joined:
    Oct 1, 2016
    Posts:
    10
    I have the same problem, but no two audio sources. Changing the audio volume programmatically does not change the audio source volume unless the component is disabled and renabled.

    Solved: Changing audio source volume does not work if the game is paused (time scale 0).
     
    Last edited: Dec 9, 2023