When testing my latest WEBGL game on Itch.io I’ve discovered that audio will not play unless the user clicks within the game window first. Then the audio starts from the beginning and catches up to where it’s supposed to be.
While researching I did find a couple of posts mentioning a workaround that involves adding the following code to some sort of user interaction. Like a button click to start the game.
Tried implementing the following code on button press before loading banks and scenes. The game will no longer load on itch.io.
It gets stuck on the “Loading game for the first time” prompt that shows before the Unity window loads.
In fact, if this code exists anywhere in my project, it seems to break the build. Even if it’s commented out, which I don’t understand at all.
I’m going to update to the latest Unity LTS version to see if that helps.
My last 3 WEBGL games have worked great using FMOD however this latest project has inexplicably become a nightmare, if anyone has any suggestions it would be a great help
User interaction before playing audio is a requirement of modern web browsers, although I have reproduced the case of WebGL working fine without user interaction in 2.02.05 and below.
While technically 2.02.06 and above is the correct and intended behaviour, I can see how the previous behaviour would be more desirable, so I have passed this onto the Dev team to see how it was previously possible to bypass this requirement.
In the meantime, the recommened approach is to prompt a user interaction before you want audio to begin.
I have not been able to reproduce this issue- and I also do not understand how having it commented out could break your build, so I suspect there may be another issue. That said, there should be no need to call mixerSuspend / mixerResume yourself in 2.02.08.
I did eventually redesign my splash screen to require the user to click in the game canvas and it’s working fine now.
I tested it a few times and each time the results were the same. Though it makes no sense I thought it couldn’t hurt to mention it. You’re probably right that something else must be going on there.