- Home /
Game pauses when user changes browser tab (even with RunInBackground)
Hi!,
I'm developing a simple webgl game, where the user has to click some buttons in a given time in order to get to the next level, but I've found a problem with the game pausing if it loses focus.
Setting the "RunInBackground" option in the player settings fixed one problem, now the game doesn't pauses when the browser loses focus, but it still freezes if the user switch the active tab on the browser.
Am I missing something? Is there a workaround to fix it?
Answer by Schubkraft · Nov 11, 2015 at 01:47 PM
We've added some more info about this in a future version of the manual:
If the Run in background is enabled in the WebGL Player Settings, or if you enable Application.runInBackground, then your content will continue to run when the canvas or the browser window loses focus.
However, it should be noted that browsers may throttle content running in background tabs. If the tab with your content is not visible, your content will only be updated once a second in most browsers. Note that this will cause Time.time to progress slower than usual with the default settings, as the default value of Time.maximumDeltaTime is lower than one second.
Is there a way to know if the tab has been switched in the current version of unity? I've figured out a way to deal with my particular problem, a simple re-arrange of the buttons will do the trick for me, but first I need to know if the tab has been switched.
you could try something like this http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-active
and then ping that info back to your webgl content (see the manual on how to send stuff between the page and unity content)
Your answer
Follow this Question
Related Questions
WebGL - Open URL in new tab? 10 Answers
Gracefully handle unsupported Web GL 2.0 Browsers 0 Answers
What is abort 127 0 Answers
WebGl Mouse Controlls and Browser Behavior 1 Answer
Can I display an Unity WebGL Game in Unity Editor ? 1 Answer