Search Unity

Disabling V Sync on Android

Discussion in '2D' started by Jakems, Apr 1, 2019.

  1. Jakems

    Jakems

    Joined:
    Nov 23, 2017
    Posts:
    1
    Hi, I was wondering if it is possible to disable Vsync for Android Devices.
    I allready unchecked the Vsync Checkbox in the Quality settings for the "Very Low" Graphic Setting,
    which is the Default one for Android Builds.
    When running the Game in the Editor the Profiler shows me, that no CPU usage goes to the Vsync
    calculation, but when I Build the Game on my Android device, Vsync takes so long to Calculate, that
    my game lags.
     
  2. MartinTilo

    MartinTilo

    Unity Technologies

    Joined:
    Aug 16, 2017
    Posts:
    195
    Hi Jakob,

    While the profiler shows V Sync the same way s it does other calculations, it is basically idle time where nothing is calculated. It just waits until the next appropriate V Blank comes along to flip the frame over.

    Here is some further explanation on commonly confusing Samples from an upcoming update to the documentation:
    • WaitForTargetFPS: Time spent waiting for the targeted FPS specified by Application.targetFrameRate. The Editor doesn’t VSync on the GPU and instead also uses WaitForTargetFPS to simulate the delay for VSync.

    • Gfx.ProcessCommands: This sample on the render thread encompasses all processing of the Rendering commands on the render thread. Some of that time might be spend waiting for VSync or new commands from the main thread, which can be seen from it’s child sample Gfx.WaitForPresent.

    • Gfx.WaitForCommands: This sample indicates that the render thread is ready for new commands and might indicate a bottle neck on the main thread.

    • Gfx.PresentFrame: This render thread sample is time spent waiting for the GPU to render and present the frame, which might include waiting for VSync.
    • Gfx.WaitForPresent: When the main thread is ready to start rendering the next frame, but the render thread has not finished waiting on the GPU to Present the frame. This might indicate that your game is GPU bound. Look at the Timeline view to see if the render thread is simultaneously spending time in Gfx.PresentFrame. If the render thread is still spending time in Camera.Render, your game is CPU bound and e.g. spending too much time sending draw calls/textures to the GPU.
    So to get to the bottom of this, you'll need to profile the game on your target device (which is always advisable, as the Editor functions fundamentally different, even to a Standalone build). Since this is an issue around the interplay of the Main thread, the Render thread and the GPU, you'll want to look at the Timeline view of the CPU Usage Profiler module instead of the Hierarchy view, which only shows the Main thread.

    One thing that happens on mobile devices is that Application.targetFrameRate is by default set to -1, from the documentation of that field:
    "- On mobile platforms the default frame rate is less than the maximum achievable frame rate due to need to conserve battery power. Typically on mobile platforms the default frame rate is 30 frames per second."

    so you might want to set that to 60, but keep in mind that you're phone will then use more power, heat up faster and as it heats up, the device might get throttled by the OS.

    Additionally I'd check if you get any changes if the VSync setting for all quality levels is set to not vsync. If you want to only affect mobile devices to not VSync you can also add this code to e.g. some startup logic of the game

    Code (CSharp):
    1. if(Application.isMobilePlatform)
    2.     QualitySettings.vSyncCount = 0