0
\$\begingroup\$

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).
\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Mar 17, 2021 at 13:09
  • \$\begingroup\$ @DMGregory like this? \$\endgroup\$
    – xcrypt
    Mar 17, 2021 at 14:51
  • \$\begingroup\$ 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.) \$\endgroup\$
    – Evorlor
    Mar 17, 2021 at 18:30
  • \$\begingroup\$ 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. \$\endgroup\$
    – Nikaas
    Mar 18, 2021 at 8:08
  • \$\begingroup\$ 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. \$\endgroup\$
    – xcrypt
    Mar 18, 2021 at 11:47

1 Answer 1

1
\$\begingroup\$

I finally found the solution! I do not have to override for WebGL to AAC at all, I just needed the default sound asset settings, and then install Windows Media Foundations. You can find it here: https://support.microsoft.com/en-us/topic/media-feature-pack-list-for-windows-n-editions-c1c6fffa-d052-8338-7a79-a4bb980a700a

Once I installed it and rebooted, my project works fine.

\$\endgroup\$
1
  • \$\begingroup\$ Hmmm, can you clarify. Is installing windows media foundations just needed on your build machine ad then the result works on web for everyone? Or is the media foundations needed on every users machine to make their browsers work with the webgl sound ? \$\endgroup\$ May 24, 2021 at 15:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .