Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Unity framerate still synced to vsync instead of target framerate

Discussion in 'Windows' started by MattWild888, Oct 19, 2022.

  1. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    Hi guys!

    Been researching into this issue a bit and have seen tons of issues with Android in relation to this kinda thing but unfortunately I'm experiencing this during Windows builds.

    Breakdown of my problem:
    I have an issue where no matter what values I set QualitySettings.vSyncCount to, and what I set Application.targetFrameRate to, when building the game and running it the framerate always returns to whatever vsync would have it as.

    Things I've tried:
    - Setting QualitySettings.vSyncCount to 0 (and making sure it stays at zero during runtime which it does)
    - Setting Application.targetFrameRate to a value that's different from the vsync target framerate (and making sure it stays at that during runtime which it does)
    - Going into quality settings and setting VSync Count to "Don't Sync"

    Strangely enough, it only becomes an issue when the project is built, in the editor it works perfectly.

    Quality settings:
    upload_2022-10-19_21-15-57.png

    Is there anything I'm missing that could be forcing my target framerate?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Can you show the code you use to configure it and then measure it? While it's not recommended (due to the fact that it will cause horrible experience for people that have monitors with a refresh rate that does not align with your target framerate), doing this should work:

    Code (csharp):
    1. QualitySettings.vSyncCount = 0;
    2. Application.targetFrameRate = 101;
     
  3. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    For debugging purposes I had this setup:


    Code (CSharp):
    1. void Update()
    2. {
    3.     QualitySettings.vSyncCount = 0;
    4.     Application.targetFrameRate = 240;
    5.  
    6.     Debug.Log(QualitySettings.vSyncCount);
    7.     Debug.Log(Application.targetFrameRate);
    8. }
    (obviously updating this every frame isn't ideal but I was making absolutely sure so I attached this simple script onto an object and let it go crazy - there were no other scripts running that were changing these variables)
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    What was the Screen.fullScreenMode set to? How were you measuring frame rate and what was it running at?

    Is there any chance your graphics driver (for instance in Nvidia control panel) is configured to force vsync?
     
  5. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    The issue was tested on 4 separate machines all encountering the same issue, the framerate was calculated via deltaTime and the game is on ExclusiveFullScreen
     
    Last edited: Oct 19, 2022
  6. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    Also worth mentioning the framerate was different on the machines depending on their refresh rates
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Can you show the code that calculates the frame rate? I cannot reproduce this in 2021.3.10f1:
    upload_2022-10-19_14-44-31.png

    I also attached my test scripts.
     

    Attached Files:

  8. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    The unity version I'm using is LTS 2020.3.38f1

    To simplify the problem I've recreated the bug on an extremely simply scene: upload_2022-10-20_20-7-35.png

    It consists of a cube as the floor that has the "Begin" script attached and the canvas and TMP Text with your FPSMeter script attached (vSyncCount is set to Don't Sync in settings) - I'll attach the scripts just incase. I've done nothing else to the project so it's entirely possible I'm missing something?

    Seems to work fine in the editor (but not in the build)
     

    Attached Files:

  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Can you also attach the DisplayInfoTextScript so it display info in your screenshot?
     
  10. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    I've added the script but unfortunately it couldn't find a definition for the RefreshRate class so I removed it:
    upload_2022-10-21_18-46-48.png
     
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    What graphics card do you have?
     
  12. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    NVIDIA RTX 2060
     
  13. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    Can you show your nvidia control panel settings? upload_2022-10-21_13-4-18.png upload_2022-10-21_13-3-11.png
     
  14. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    My settings:
    upload_2022-10-22_13-27-13.png
    upload_2022-10-22_13-27-49.png
     
    floatingfactory likes this.
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    MattWild888 likes this.
  16. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    Ohhh okay, would this limit fps for all unity games? - Just wondering why I haven't noticed this until now lol
     
  17. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    It's working! - Thank you, your help was great :D

    Just as a side thing, is there a good way to tell when graphics card settings are overriding application settings during runtime?
     
  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,756
    It would limit FPS for all games running on your computer, not only ones made in Unity.

    Not really. Those driver settings are made so the application would have no chance of detecting or defeating them.
     
  19. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    I see, thanks for all your help :)