Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Is there any workaround to make WebGL game work in background?

Discussion in 'Web' started by Pizel, Apr 16, 2024.

  1. Pizel

    Pizel

    Joined:
    Feb 2, 2022
    Posts:
    4
    I know that modern browsers are throttling background tabs and making setTimeout() or setInterval() call once per second, but is there any possibility to prevent it from doing so?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,581
    As a web developer you have practically zero control over what the Browser does or decides to do.
     
  3. Pizel

    Pizel

    Joined:
    Feb 2, 2022
    Posts:
    4
    I mean I've tried to use things like HackTimer.js or worker-timers package, but I'm not sure if that works with WebGL. Anyway I thought there are some solutions for it aswell.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,581
    You can see by its repository it was last updated 7 years ago. That's ages in tech time. You can assume it no longer functions since Browser developers learned of that "hack" and prevented it. This is what you can expect to happen with any such tool so it's best not to rely on it.
     
  5. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    602
    Yeah but it can give you bad performance (you can change the 30 by any number you want) :

    Code (CSharp):
    1. QualitySettings.vSyncCount = 0;
    2. Application.targetFrameRate = 30;
     
  6. Pizel

    Pizel

    Joined:
    Feb 2, 2022
    Posts:
    4
    I have already tried that, but it does not change anything.
     
  7. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    602
    What is your unity version? I remember that i have tested on unity 2022 few months ago and it was working but like i was not happy of the performance, i'm not sure that i have keep the project file. I'm gonna take a look but i can't promise anything.
     
  8. Pizel

    Pizel

    Joined:
    Feb 2, 2022
    Posts:
    4
    My unity version is 2023. Anyway can you check if it is working on your version?
     
  9. Armynator

    Armynator

    Joined:
    Feb 15, 2013
    Posts:
    68
    No. Any workaround you could try might not work with any browser/hardware/OS combination and will behave random/incorrectly.

    You'll have to design your game around this limitation. It should be quite easy if done right from the beginning.