Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Game starts to run too fast on Android after it has been minimized for a while

Discussion in 'Android' started by Extiward, Apr 28, 2021.

  1. Extiward

    Extiward

    Joined:
    Nov 13, 2016
    Posts:
    9
    Hi!

    I've encountered a peculiar issue with my game only when building it for Android (haven't tested iOS for lack of devices; Editor and WebGL builds work fine).

    I'm using on demand rendering almost exactly as described in this Unity blog post. And it has been working fine up until around Unity 2020.1 (not entirely sure which version exactly). But since then if player sends the game to the background on Android and resumes it after a while (from several seconds and up) game speed will have increased as if timescale had been increased. The only fix will be to close and reopen the app.

    Here is code excerpt of the on demand rendering implementation:
    Code (CSharp):
    1. using TMPro;
    2. using UnityEngine;
    3. using UnityEngine.Rendering;
    4.  
    5. public class TestScript : MonoBehaviour
    6. {
    7.     [SerializeField] private TextMeshProUGUI debugText = default;
    8.     [SerializeField] private GameObject square = default;
    9.  
    10.     private void Awake()
    11.     {
    12.         // Set standard framerate to be 60 and render at 30 fps
    13.         // https://docs.unity3d.com/2021.1/Documentation/ScriptReference/Rendering.OnDemandRendering-renderFrameInterval.html
    14.         QualitySettings.vSyncCount = 0;
    15.         Application.targetFrameRate = 60;
    16.         OnDemandRendering.renderFrameInterval = 2;
    17.     }
    18.  
    19.     void Update()
    20.     {
    21.         // Set fps to 60 when player interacts with the game, else 30 fps
    22.         if (Input.GetMouseButton(0) || (Input.touchCount > 0))
    23.         {
    24.             OnDemandRendering.renderFrameInterval = 1;
    25.         }
    26.         else
    27.         {
    28.             OnDemandRendering.renderFrameInterval = 2;
    29.         }
    30.  
    31.         // Draw rotating sprite to get better idea of game speed
    32.         square.transform.Rotate(Vector3.forward, 50 * Time.deltaTime);
    33.  
    34.         debugText.text =
    35.                $"vSyncCount: {QualitySettings.vSyncCount}\n" +
    36.                $"Target FPS: {Application.targetFrameRate}\n" +
    37.                $"Render Frame Interval: {OnDemandRendering.renderFrameInterval}\n" +
    38.                $"Time scale: {Time.timeScale}\n" +
    39.                $"Effective FPS: {OnDemandRendering.effectiveRenderFrameRate}\n" +
    40.                $"Delta Time: {Time.deltaTime}";
    41.     }
    42. }
    I've filed a bugreport a few weeks ago but it hasn't been processed yet, so I'm turning to forums for help. Was using Unity 2021.1.2. at the time of reporting, the issue is still there on 2021.1.3. and 2021.1.4. This might not be a bug at all, but simply my ignorance.

    Has anyone encountered something similar?
     
    Lorrak likes this.
  2. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,592
  3. Extiward

    Extiward

    Joined:
    Nov 13, 2016
    Posts:
    9
    radiantboy likes this.
  4. Lorrak

    Lorrak

    Joined:
    Sep 17, 2019
    Posts:
    38
    its not been fixed, using 2021.3f and just tested on android OS 8.0.0 Api-26, and the performance stays, if I had 30fps after minimising then again using the app fps jumps to 50fps and stays
    ???
    I could add I had noticed it back in 2019lts