Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug Audio muting doesn't work in WebGL build

Discussion in 'Audio & Video' started by flanktus, Nov 10, 2023.

  1. flanktus

    flanktus

    Joined:
    Apr 25, 2020
    Posts:
    1
    Hi, I'm creating a browser game and I have a problem with sound. While the game is displaying video ad, the game audio should be muted, I created a separate function for this, which works in the editor, but does not work at all in the finished WebGL build, anyone have an idea why?

    Code (CSharp):
    1. public void OnAdRequested()
    2. {
    3.         mainMixer.SetFloat("masterVolume", -80f);
    4.  
    5.         Debug.Log("OnAdRequested()");
    6. }
    7.  
    8. public void OnAdCompleted()
    9. {
    10.         if (playMusic || playSound) mainMixer.SetFloat("masterVolume", 0f);
    11.  
    12.         Debug.Log("OnAdCompleted()");
    13. }
    Interestingly, the code is invoked correctly, as I checked in the browser console. All references are set correctly, I really have no idea what could be wrong anymore.

    Unity Version: 2022.3.12f1

    upload_2023-11-10_16-9-29.png
    upload_2023-11-10_16-9-58.png
     
  2. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    435
    I am sincerely sorry to say that the AudioMixer and OnAudioFilterRead are audio features that are not available specifically on WebGL. Here's a page listing the what's available for audio in that context:

    https://docs.unity3d.com/Manual/webgl-audio.html