Search Unity

Bug vsync overrides targetFrameRate in windowed app

Discussion in 'General Graphics' started by andyz, Jan 12, 2021.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,277
    If do this in code (Unity 2020.1.14 HDRP):
    Code (CSharp):
    1. QualitySettings.vSyncCount = 1;//also if this done in project's QualitySettings
    2. Application.targetFrameRate = 30;
    then in the editor it runs at 30 fps, but when built to standalone windowed it runs at 60 fps (vsync presumably).
    Bug or feature?!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    andyz likes this.
  3. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,277
    Thanks I do not know how I missed that, I never new... perhaps a console warning would help if set to no avail and as to the Editor NOT behaving in the same way - surely a bug.
    Does that mean screen-tearing is bound to happen with targetFrameRate set? Hmm at least it should be smooth with the latest improvements...
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    I believe
    targetFrameRate
    will also enable VSync if below the native refresh rate, but I don't know for sure. All the documentation hints that that might be the case, but also only references that behavior for mobile devices.

    In the editor I believe VSync is always enabled and cannot be disabled for either the scene or game views, even when running at high framerate. Indeed the scene view often runs at several hundred fps w/o tearing, as can the game view. It's possible the
    vSyncCount
    setting is ignored in the editor, though it's not mentioned in the documentation, and I've not needed to use that setting in the last 6 years