Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Locking target FPS at 90 Gives me 90 - 80 fps, and locking fps at 60 gives me 60 - 50 fps

Discussion in 'Android' started by yng_omr, Nov 23, 2023.

  1. yng_omr

    yng_omr

    Joined:
    May 9, 2022
    Posts:
    3
    I built my game for android with a locked fps at 90, which gives me 90 - 80 fps, and when I lock it at 60 the game gets 60 to 50 fps, this made me confused, shouldn't locking the fps at 60 results in consistent 60 fps, if locking target fps at 90 gives me 90 to 80 and never even drops to 70?

    I figured maybe the device gave me enough resources to reach the target fps, but I'm not sure that's true. If that's the case is there a way to demand more from the device?

    My game looks better at consistent fps if anyone was wondering why lock the fps if I can get more. Any ideas or help is appreciated.
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,952
    without information not sure how we are expected to help.

    How are you "locking" your FPS? you havent said how? Are you turning on vsync? Are you setting Application.targetFrameRate?

    Neither of these will "lock" the framerate but simply set a max cap and they both work differently.

    Without seeing profiling outputs etc, its hard to tell what the issue is coupled with not knowing the method in use. How are you reading your FPS? Stats window in editor? Custom FPS display script? 3rd party overlay? etc

    Context is king here on the forums so please be as detailed as you can and provide shots of all relevant telemetry if you are hoping to get some troubleshooting assistance :)
     
  3. yng_omr

    yng_omr

    Joined:
    May 9, 2022
    Posts:
    3
    I am setting a max cap using Application.targetFrameRate at the start of the game and I use a 3rd party overlay to read the FPS
     
  4. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,639
    This topic pops up here every couple months.
    It is not possible to lock the framerate on a regular system. In the greater sense that is why real time computing requires very special software on bare metal - a typical OS makes it impossible.
    Reason is your software can NOT predict:
    1. how long it's own next tasks will take due to the extreme complexity
    2. whether the OS will suspend your thread to let other threads work

    The result is that one can provide an upper bound (because you just give up/idle your thread if you have computed too fast) but not a lower bound.
     
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,775
    Unity made a blog post on the topic a few years back. Short version is
    Application.targetFrameRate
    is made to be efficient rather than exact. For exact rendering you have to look into manually controlling updates and renders.

    Some sample code and links to a github repository are in the blog post if you want to see their approach.

    https://blog.unity.com/engine-platform/precise-framerates-in-unity
     
    Last edited: Nov 24, 2023
  6. yng_omr

    yng_omr

    Joined:
    May 9, 2022
    Posts:
    3
    Very insightful blog, thank you!
    but I realized trying to lock the frame rate can be costly, and it won't work for the wide range of devices I'm targeting. The best thing to do is, to have a lot of quality settings available for the players and let them finetune the game to their liking.
     
  7. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,252
    You shouldn't target high frame rates on mobile anyway due to thermal throttling and power drain. Unless it's absolutely key to your game, keep it at 30fps.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,535
    It depends on the game, but I absolutely disagree with the above statement.

    In an era where 90 and 120hz phone displays are common, the whiplash when running a 30fps game is tremendous. Have the option for 30fps, but don't default to it.
     
    IOU_RAY, Stardog, Ryiah and 4 others like this.
  9. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,252
    I suppose you render full resolution on those devices too? Just cause you can, doesn't mean you should...
     
  10. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,535
    I actually do. We default to 80% of the full resolution depending on the device, but the options are there.

    For our new game we’re attempting to pick a default resolution based on performance (we keep dropping it if it can’t get a smooth 60fps), but we start at native. New-ish mid range and above devices don’t really need to drop resolution.
     
    Last edited: Dec 3, 2023
    MadeFromPolygons likes this.
  11. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,908
    Have you seen these posts? I am targeting 90fps on modern phones and 60fps on older, and had to do this:

    https://forum.unity.com/threads/set-screen-refresh-rate-on-android-11.997247/#post-8164832
    https://forum.unity.com/threads/set-screen-refresh-rate-on-android-11.997247/#post-9083293

    TLDR. Use the MainActivity.java modified to your game, and set your targetFrameRate at least 1 higher than what you want.

    Also, for performance in general, it seems SetResolution to 80% is faster than the scaling from ScalableBufferManager to 80%. And it will also scale the UI down, which can be the main source of overdraw.

    There are also issues with some android OS's will auto-reduce to 60fps when not being touched for 5 seconds, but that's another story.
     
    AcidArrow likes this.