Search Unity

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

Question How To change Display RefreshRate

Discussion in 'General Discussion' started by MohamedTun, Jul 31, 2023.

  1. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
    Hi, since unity Won't allow you to change the display refresh rate or even setting a 60fps on a 90hz or 144hz display, there is a way aroud it ! Google have already an api for it Here. I'm new for android studio and java so I couldn't get it to work and the documentation about it not very clear. I spend the last week trying to find a solution, I did manage to show an android toast message even showing battery charging capacity but i didn't succeed to change the display RefreshRate. I really need help !
    proble.jpg
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,725
    I've never heard of this being the case. How have you been trying to do it before this?
     
  3. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
    You Can't change the display refresh rate in unity. The only option you have is target frame rate wich responsable of changing the game fps not screen refresh rate, add to that unity won't allow you to get 60fps on a 90Hz,144,165 because they said that the fps need to be divisor of 2 and with no decimal digits meaning that a 90 hz you can achieve 90,45,30.144hz display 144,72,48 etc. disabling frame pacing also won't help. In older versions of unity you can get 60 on a 90hz device but the fps is not stable and looks worse than stable 45. So only solution to fix it is to change the display refresh rate to 60 so you can achieve a locked smooth 60fps
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,725
  5. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,725
    Again I've never heard of this being the case.
     
  7. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,496
    I think you missed Screen.SetResolution. Refreshrate stores refresh rate as fraction, so you could target 59.97 or whatever that one odd refresh rate was in CRT times. Assuming your display supports it. You cannot set refresh rate to random values. You need to use ones supported by your display, and those have to be enumerated.
    https://docs.unity3d.com/ScriptReference/Screen-resolutions.html

    That applies to desktop. On android secondary packages like cardboard can interfere with resolution in strange ways, for example, preventing you from setting 90Hz. And of course, on desktop, user can mess with the drivers, setting overrides...
     
    Ryiah likes this.
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,725
    The API that they've linked to allows you to set arbitrary values, and if the device chooses not to ignore it it will try to match it as close as possible.
     
    Last edited: Jul 31, 2023
  9. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
    res.refreshRateRatio shows that my phone can accept 90,60 but when i set the refreshrate to 60 nothing happenes. There is a build in refresh rate indicator in android it should switch to 60 like when I enter youtube app
     
  10. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,725
    Who is the manufacturer and what is the model of the phone?
     
  11. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
    xiaomi 11lite 5g ne supports 90 and 60 and as I said when I enter youtube app the screen automatically switches to 60 and I can feel it and see the indicator switches to 60
     
  12. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,496
    There's
    https://docs.unity3d.com/ScriptReference/Rendering.OnDemandRendering.html
    https://docs.unity3d.com/ScriptReference/Rendering.OnDemandRendering-renderFrameInterval.html
    https://docs.unity3d.com/ScriptReference/QualitySettings-vSyncCount.html
    and
    https://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
    All of which can affect refresh rate.

    Also I absolutely would not trust built-in refresh rate indicator. You need to check the rendering rate from within unity. Implement framerate counter in unity, see its values.

    Also, you're asking in a wrong forum. General is not support forum.
     
  13. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,725
    Speaking of which here's a free one.

    https://assetstore.unity.com/packag...ate-fps-counter-stats-monitor-debugger-105778

    Okay, I've looked up and confirmed the phone supports it, but I've also looked up and confirmed that people outside of Unity have been having trouble getting that model to change refresh rate.
     
    MohamedTun likes this.
  14. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
    I already have an fps counter and still showing 90 or 45 no 60 the only way I can achieve 60 is to switch screen refreshrate manually to 60
     
  15. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
    Can You give me link pls because in some apps the phone switch to 60 automatically and seamlessly
     
  16. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,496
    This sort of thing doesn't take a lot of time to write, So.... (-_-)

    I vaguely recall having plenty of trouble switching refresh rate on android in one of the projects.

    Problem one was that by default application was running at 60 and didn't want to go to 90 even if I demanded it. To be more specific, it sometimes didn't want to go to 90. I don't rememebr what I needed to do, I remember being annoyed by it. It involved plenty of "dances with tambourine".

    Problem two was application completely ignoring everything related to ondemand rendering when cardboard is installed. It was running at 60 fps and draining battery no matter what we did. Apparently cardboard did *something* under the hood which effectively disable frame skips/etc.

    In the end I just assumed that android is not as reliable to PC when it comes to resolution switching, granted this wasn't top priority to begin with.
     
  17. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,725
    MohamedTun likes this.
  18. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
  19. MohamedTun

    MohamedTun

    Joined:
    May 13, 2021
    Posts:
    33
    In android You can't get frame rate above your screen refresh rate no matter what you do and vsync is useless and also you can't set any target frame rate you want