GameDev problem: the music in our WebGL game on itch.io won't start until the user clicks in the window. Unity claims this is a browser limitation (no autoplay):

docs.unity3d.com/Manual/webgl-

... but the user has *already* clicked to load and launch the game, so it seems there should be no reason to require another click. I know I've seen WebGL games on itch that don't have this problem.

Does anyone know a workaround?

@peterdrake Put a quick interstitial scene at the start with a "START GAME" button?

@LouisIngenthron That should work, but we'd prefer to have music playing over the initial title menu. Otherwise the player has to click twice: once to go to the title menu and start the music, then again to start the game proper.

@peterdrake Right, I think that's the expected behaviour for WebGL. If you want to make it a little more seamless, you can put in a brief animation of the studio and game logo in between, kind of an animated entrance for the main menu. Then the button is there to ensure the player gets to see it all!

@peterdrake It does. Because if it didn't, I'd be mad at the browser for autoplaying.

@LouisIngenthron But it's not autoplaying. It doesn't do anything until you click on itch's load game button.

@peterdrake So then it sounds like the real problem is Itch's redundancy within web browsers.

@LouisIngenthron It's not just itch, because this happens in a local web build, too.

@peterdrake Maybe it has something to do with the permissions/iframe configuration in the HTML code? Looking at that example you posted, I see they explicitly set an allow=autoplay.

@peterdrake I think the way the unity web stuff works is that first click is just javascript to load that app into the frame, so you'd actually need to click into the frame afterwards to give it focus. I know in the tiny bit of web stuff I've done I didn't do any javascript preloading so this wasn't an issue.

@peterdrake is the unity loader editable? you might be able to have that part auto-load and have a clickthrough on the game itself. I don't develop with unity myself I'm just going off how it webgl works in general (I've done some c++/emscripten ports)

Otherwise I'd just have a splash to click to go to the menu, that's what most unity games seem to do on web.

@raptor85 I don't know about the loader; webdev is not my area of expertise.

We could add another layer of title screen, but I've seen other games where music is playing on the first WebGL screen, so there must be a way to do it.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.