Search Unity

Application.targetFrameRate not working

Discussion in 'iOS and tvOS' started by El3et, Feb 6, 2013.

  1. El3et

    El3et

    Joined:
    Jan 19, 2011
    Posts:
    97
    Hi guys been doing on this issue for hours now, Application.targetFrameRate is not working no matter what I do.

    I've tried changing it to 20, 25, 22, 60 but it doesn't seem to register my change.

    I know it doesn't work with vSync on so my quality settings are set to fastest and the project is for iOS.

    Any ideas why its not working correctly?

    Thanks.
     
  2. john-essy

    john-essy

    Joined:
    Apr 17, 2011
    Posts:
    464
    We set ours in the Start method Application.targetFrameRate = 30; ours works fine how exactly are you setting your's up?

    Also remember if your game is running at 15 FPS and you set your target frame rate to 20 it will make no difference the game will still run at 15FPS
     
  3. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
    Application.targetFrameRate doesn't work in the editor. Is that where you are testing it?

    Also, the maximum screen refresh rate is 60 FPS in iOS, so you should set it to 60 or a number that can be multiplied by an integer to get 60 (30, 20, 15, etc.). That way your screen is updated every screen refresh or at a consistent number of refreshes.

    The Unity iOS default is 30, so you do not need to set it if that is what you want.
     
    cyanspark, Fenikkel and Azurne like this.
  4. john-essy

    john-essy

    Joined:
    Apr 17, 2011
    Posts:
    464
    Target framerate works in our editor?

    Although we are using a custom FPS counter.
     
  5. El3et

    El3et

    Joined:
    Jan 19, 2011
    Posts:
    97
    Thanks guys. I solved the problem. It seems to work perfectly fine when attached to an empty gameObject but when attached to the camera it does work. Thanks for your help.
     
    RickyHoughton likes this.
  6. Neeko

    Neeko

    Joined:
    Mar 9, 2012
    Posts:
    24
    I had to turn off V-Sync in order to get Unity to adhere to the target framerate.

    // Turn off v-sync
    QualitySettings.vSyncCount = 0;
     
  7. budwheizzah

    budwheizzah

    Joined:
    Apr 3, 2014
    Posts:
    13
    Nothing works. Everything I do gives 60 fps locked on v-sync. I can SEE v-sync in the damn profiler.
    60 fps and nothing else. Unity is LOCKED and FORCING v-sync. I have tried Application.targetFrameRate = -1, turning off v-sync in quality, turning it off in the code (post above) turning it off at the video card level... I still see v-sync in full action in the profiler (the big thick yellow bar of death, she who locks me at sixty, she who will not relent, etc) and I CANNOT turn it off yet desperately need to.

    Why is something so simple ABSOLUTELY impossible with Unity?! This is extremely shoddy and from the forums no one has a solution AT_ALL. If it works for some of you - great - but it generally doesn't work at all, since a lot of people complain about this. It's not good when it applies to a few single obscure hardware configs. This needs to work for everyone. Currently v-sync does whatever the heck it bloody pleases.
    Can I get this junk to relent? I'm using Radeons 6970, 7870 and 8750M... same garbage on all of them. On the 8750M it's so pathetic I can't even turn off THE BUFFERING.... I'm developing for Virtual Reality, needless to say buffering is equivalent to physically assaulting your player by reaching into his stomach and pulling the contents out.

    Seriously Unity... seriously. This v-sync control works like junk.
     
  8. budwheizzah

    budwheizzah

    Joined:
    Apr 3, 2014
    Posts:
    13
    Just in case anyone goes full-retard on this issue and starts poiting to a bunch of random things when people like us bring up this major, major bug: here are a few screenshots showing how this engine is clearly broken when it comes to v-sync and IGNORES what the user has set.

    Even the profiler here shows it clearly "F*** you developer, I'm syncing no matter what you say", just like a good stubborn piece of junk. Meanwhile Portal 2 running off Valve Source runs normally like any engine should. Also screenshot that just to make sure people don't try to get cute asking "Did you (insert condescending obvious thing to check here)".

    This issue has gotten me fed up. VR is extremely buffer sensitive. V-Sync buffers. It renders VR unusable. Unity, the best option to develop for the Rift, is now unusable.... for the Rift. Sad. V-Sync = VR cancer. This engine is as good as non-existent for me.
     

    Attached Files:

    BigDandBigDandBigD and Gamba04 like this.
  9. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You're setting vSyncCount to -1, but the only acceptable values are 0, 1, 2. You should be setting it to 0.

    You're setting Application.targetFrameRate to 9999, you can set it to -1 to not limit the framerate.

    I realize you said you tried the above, but I'm going off of your images.
     
  10. budwheizzah

    budwheizzah

    Joined:
    Apr 3, 2014
    Posts:
    13
    Yes, you would be correct. At that point honestly I was thinking f* it :)

    Ok, here's the scoop. This is after all NOT Unity's fault. However this was NOT easy to notice despite its not being that very much hidden. I noticed that going vSyncCount=0; in *ANY* update function would finally solve the issue.

    HOWEVER, if it was in a Start() function, no go. This could only mean one thing. The opposite is being called somewhere else, right? Well I couldn't recall for the life of me having done this myself. On the other hand a lot of us (in my case, totally) get libraries either off the asset store or for some specific support, in my case the OVR libs for example.

    I immediately realized some of the imported library code MUST be calling the opposite... vSyncCount=1... so I ran a search through the entire bloody project folder and sure enough, I found the culprit. Furthermore it so happens I have a fellow developer, not doing VR, who also had the problem due to another lib, also not written by himself but rather imported. I helped him fix his problem while I was at it. A crusade against v-sync if you may :)

    Bottom line if the vSyncCount is being altered somewhere else and you're not aware of it.... DUH... for sure you're gonna have problems. I promptly took OUT the bloody call and put in my own single vSyncCount=1in a Start() function like it should be and - voila. Finally. The app can unleash insane 450fps rates and oddly enough without an ounce of screen tearing (also detrimental to VR but less so than input lag).

    What really stunned me here is that even through the video card's own "Do not ever V-Sync" option, v-sync would still take effect. That part I still don't get - it should override and doesn't. Is it Catalyst? Is it Unity? Not sure at this point.

    All in all to save everyone this wild goose chase.... just run a bloody search through your whole project folder for either targetFrameRate or vSyncCount and likely you'll find a lib you imported from the outside to contain the call somewhere, setting it to a value you're not expecting.

    Boy am I glad this was resolved. The difference for VR is day and night. So smooth without the frame cap.
     
    SgerbwdGwyn likes this.
  11. Graham-Dunnett

    Graham-Dunnett

    Administrator

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    I'm glad this major, major ... engine is clearly broken bug got fixed.
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Why can't you fix all bugs that way? All this "spend programmer time fixing bugs and releasing new versions" stuff sounds like a waste of time.

    --Eric
     
  13. HgM3rK

    HgM3rK

    Joined:
    Jul 11, 2015
    Posts:
    2
    budwheizzah was last seen:
    Jun 3, 2015
     
    Fenikkel, Rayeloy, RaoulWB and 2 others like this.
  14. elenzil

    elenzil

    Joined:
    Jan 23, 2014
    Posts:
    73
    ding ding ding! thank you.
     
  15. dttngan91

    dttngan91

    Joined:
    Nov 21, 2013
    Posts:
    80
    I am facing the issue where the same source code running on Unity editor of Window machine vs Mac machine, leading to 2 different FPS, one is 30, one is 60, already turn off vSyncCount. Have anyone had idea why?
     
    Opeth001 likes this.
  16. shakenbake444

    shakenbake444

    Joined:
    Jul 23, 2019
    Posts:
    21
    Man, i was hoping this would solve my problem but didn't. I just want to set my frame rate at a fixed 60 fps. Why is that so hard? I'm also checking the fps from the "stats" window in the game window. I hope that's actually correct and not just giving me the refresh rate of the card or monitor. I tried putting the QualitySettings.vSyncCount = 0; and Application.targetFrameRate = 60; in my update functions and no go. Tried doing this on game objects and main camera. nothing. Tried searching through my project for calls for these settings and found nothing. Any guidance would be appreciated.
     
  17. DBarlok

    DBarlok

    Joined:
    Apr 24, 2013
    Posts:
    268
    Create a fresh project and test if you can change the framerate. If you can, the problem is in your code.
     
  18. dispatch_starlost

    dispatch_starlost

    Joined:
    Nov 17, 2017
    Posts:
    37
  19. ruudvangaal

    ruudvangaal

    Joined:
    May 15, 2017
    Posts:
    27
    Note btw that for example in the nVidia driver on PC I can still force vsync, no matter what the application (Unity) says. So also in that case, it's not really Unity's fault. Setting vsync is not really the realm of application programmers other than a single call to a driver. Hard to make bugs in such a call. ;-)
     
  20. TeJIePuziK

    TeJIePuziK

    Joined:
    Apr 19, 2020
    Posts:
    1
    In Unity 2020 or higher or Android SDK 11 uncheck this:
     

    Attached Files:

  21. blackfxx

    blackfxx

    Joined:
    Nov 21, 2013
    Posts:
    4
    you saved my day!
     
  22. FnSolo

    FnSolo

    Joined:
    Mar 5, 2023
    Posts:
    1
    In a summary,
    Solution that worked for me:

    private void Start()
    {
    QualitySettings.vSyncCount = 0;
    Application.targetFrameRate = 10;
    }


    For some reason the default vSyncCount makes fps unlimited in Build, ignoring the target(Tho works fine in editor's Game), at least if you have "Vsync - Fast" in your nVidia panel.
    If it doesn't help, put in Update(), but in that case something may be wrong with the code or the settings, that influence it later than the Start(). Limiting to 10 just to make it noticeable, write yours. Also the "1" for Vsync didnt work for me.
     
  23. mellasgdv

    mellasgdv

    Joined:
    Jun 26, 2021
    Posts:
    6
    *****NOTE**** : If You're Calling it on The Awake Method It Would Not Work ,
    But You Have to Call It On The Start Method
     
    IgorAherneBusiness and kyuskoj like this.