How to play sound in WebGL build in Unity?

I have a project that works fine when I build for windows, but doesn't work when I switch platform to WebGL. The [SerializeField] AudioClip variables in the inspector are all 'missing', even after I check 'override for WebGL' convert to AAC. And when I try to link any audio file to an AudioClip within a WebGL build in the inspector, it doesn't seem to work.

How do I get sound to play within WebGL?

To recreate the problem:

• Switch platform to WebGL.
• Create a new Script in any recent unity version, then add a [SerializeField] AudioClip x.
• Put that script on a new gameobject and try to link an audio asset to it (default import settings, however don't forget to check 'override for WebGL' to AAC, otherwise you will get compiler errors when you switch platform).
• I've never experienced any specific difficulties playing audio in a WebGL build - every time I've tried it, it "just works," the same as on desktop. Can you edit your question to include a Minimal Complete Verifiable Example, walking us through all the steps to reproduce the problem in a new, empty project? This should include the exact encoding of your source assets, how you've imported them into your project, and the script that is playing them. Mar 17 '21 at 13:09
• @DMGregory like this? Mar 17 '21 at 14:51
• Step 1. Don't build for WebGL. There is no step 2. (I have decent experience with WebGL + Unity, and have come to the conclusion that it is not worth it.)
– Evorlor
Mar 17 '21 at 18:30
• I have the same problem. It is related to browsers not initializing audio if there is no mouse interaction (it is made to prevent annoying sound adds). If you spam the mouse button while the Unity logo is displayed you will see in the browser log that then the audio module is loaded (otherwise there is error log for no audio module). That fixes it for some users but for me still no sound. I agree with Evorlor and I dont bother with WebGL anymore, too many problems and unexplainable performance drops on half the machines tried. Mar 18 '21 at 8:08
• Not doing WebGL is not an option as I've made this project from the beginning knowing that we were gonna support WebGL. Just hope I can find a fix for the audio. Mar 18 '21 at 11:47