Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on t

Discussion in 'WebGL' started by bustedbunny2, Feb 23, 2022.

  1. bustedbunny2

    bustedbunny2

    Joined:
    Oct 27, 2021
    Posts:
    25
    Unity 2021.2.12f.
    Basically I have 0 sounds on auto start. I only register callbacks on pointer enter / click with sounds.
    Yet, none of my sounds get to work, except those that get loaded in next scene.
    Obivously, in editor everything is perfect.

    In build console I see about 20 those warnings, nothing red.
     
    peq42 likes this.
  2. peq42

    peq42

    Joined:
    Mar 4, 2022
    Posts:
    73
    I'm experiencing the same issue on Unity 2022.1.18f1
     
  3. Hypertectonic

    Hypertectonic

    Joined:
    Dec 16, 2016
    Posts:
    75
    This is normal. Because of some limitations of WebGL, you can't have audio auto start. You need the user to click something on the site so the audio context can initialize. The best thing is to have a loading screen with a "click to continue" button.

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

    DudoTheStampede

    Joined:
    Mar 16, 2015
    Posts:
    79
    That's not a WebGL limitation but a browser one.
    The problem with WebGL is that you get that even if you are not playing sounds on Start and I thinks that's a Unity issues that I hope they will fix.

    It's only a warning so it shouldn't affect your application.
     
    peq42 likes this.
  5. peq42

    peq42

    Joined:
    Mar 4, 2022
    Posts:
    73
    doesn't work, I've tried. I made a page with a button that when clicked adds an iframe to my game's index.html(so the game only starts loading after you click the button) and the issue is still there.
     
  6. DudoTheStampede

    DudoTheStampede

    Joined:
    Mar 16, 2015
    Posts:
    79
    Actually like that you won't solve the problem!
    Now it's the iframe that fires the Warning. I think that as soon as you click on the iframe the warning stops appearing.

    To do as suggested I would place all the unity instancing in the button click callback.
    I try with an example (using jQuery):
    Code (JavaScript):
    1. $(document).ready(function(){  
    2.     $("#loadButton").click(function() {
    3.         var script = document.createElement("script");
    4.         script.src = loaderUrl;
    5.         script.onload = () => {
    6.             createUnityInstance(canvas, config, (progress) => {
    7.                 progressBarFull.style.width = 100 * progress + "%";
    8.             }).then((unityInstance) => {
    9.                 gameInstance = unityInstance;
    10.             }).catch((message) => {
    11.                 alert(message);
    12.             });
    13.         };
    14.         document.body.appendChild(script);
    15.     });
    16. });
     
  7. peq42

    peq42

    Joined:
    Mar 4, 2022
    Posts:
    73
    Fixed the issue by reloading all assets(just reloading unity wont fix it, probably something to do with the cache of the files? idk)