Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to maintain 30fps even during screensaver and background operation

Discussion in 'Editor & General Support' started by davepl, Apr 3, 2019.

  1. davepl

    davepl

    Joined:
    Jun 3, 2014
    Posts:
    14
    I have set

    Application.runInBackground = true;

    ..and yet as soon as the screensaver kicks in, my game drops to 2-3 frames per second. I know this because it's actually rendering electronic sign data that gets pushed out to a sign, and the updates fall to a very slow pace during screensaver/sleep. It is precisely because I use it to render the sign data that I need it continue apace at all times.

    I'm not very CPU intensive and barely touch the GPU, and when I wrote it as a C++ prototype, it worked fine in the background.

    I can understand that maintaining visual frame rate while hidden is likely not a priority for Unity, but since I need to accomplish it, any suggestions?
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    2,431
    Hello,

    Have you tried setting Application.targetFrameRate = 30 or 60 and maybe QualitySettings.vSyncCount = 0 ?

    I have no particular insight into potential throttling that could happen when run in the background but this could also be the OS throtteling the GPU maybe?

    Have you tried connecting to the build with the Profiler running on another computer?

    If you don't have another computer available and can't switch back into the editor to stop your profiling session before the relevant frames run out of the 300 frames max of the profiler window, you could also try disabling the profiler through code from the player e.g. 200 after the screensaver came up / performance dropped by setting Profiler.enabled. Maybe you'd also want to not profile with the editor running on the same machine and just profile into a file and load that later in the editor. For that case you can use Profiler.enableBinaryLog. The limit of 300 frames sadly still applies for the binary log file though (the profiler will only load the last 300 frames while the file can grow further than that.