Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Discussion refreshRate obsolete, use refreshRateRatio instead + SetResolution fourth argument

Discussion in 'Scripting' started by ShidaPenns, Feb 19, 2023.

  1. ShidaPenns

    ShidaPenns

    Joined:
    May 9, 2013
    Posts:
    11
    'Resolution.refreshRate' is obsolete: 'Resolution.refreshRate is obsolete. Use refreshRateRatio instead.'

    'Screen.SetResolution(int, int, FullScreenMode, int)' is obsolete: 'SetResolution(int, int, FullScreenMode, int) is obsolete. Use SetResolution(int, int, FullScreenMode, RefreshRate) instead.'

    So I had these two issues, just warnings about obsolescence that I could ignore of course. But I wanted to solve it. But I couldn't find anything online. Which is to say... I'm actually kind of proud of myself for solving this, as I'm an almost complete beginner, just started recently. Only able to do this at all thanks to ChatGPT, I'm disabled and learning is a painfully stressful thing.

    Anyway, so, I had this (resolutions is a Resolutions[] array set to Screen.resolutions):
    Code (CSharp):
    1.         for (int i = 0; i < resolutions.Length; i++)
    2.         {
    3.             if (resolutions[i].refreshRate == refreshRate)
    4.             {
    5.                 filteredResolutions.Add(resolutions[i]);
    6.             }
    7.         }

    And worked out I can replace refreshRate with refreshRateRatio.value. So, this:
    Code (CSharp):
    1.         for(int i = 0; i < resolutions.Length; i++)
    2.         {
    3.             if (resolutions[i].refreshRateRatio.value == refreshRate)
    4.             {
    5.                 filteredResolutions.Add(resolutions[i]);
    6.             }
    7.         }
    But the next one was a lot more difficult, everything I tried wasn't working and ChatGPT was giving wrong answers that didn't work. But I eventually worked out how to properly set the fourth value of SetResolution which expects a RefreshRate type (rRate is my refresh rate value here, an int set to "60"):
    Code (CSharp):
    1.         // Create a new RefreshRate object with the given refresh rate
    2.         RefreshRate refreshRate = new RefreshRate();
    3.         refreshRate.numerator = (uint)rRate;
    4.         refreshRate.denominator = 1;
    5.         // Call Screen.SetResolution to set the resolution and refresh rate
    6.         Screen.SetResolution(width, height, FullScreenMode.ExclusiveFullScreen, refreshRate);
    I'm not actually posting this to boast (I'm sure it's nothing special, like I said I'm an almost complete beginner), but because I couldn't find this stuff anywhere (searching by the warning messages). But I'm sure other people know and I could've asked about it. It's stressful to do that though, hence why I'm using ChatGPT a lot for help. Anyway I hope this'll help people who also don't like just ignoring warnings. :p
    If I got anything wrong, please correct me!
     
    Last edited: Feb 19, 2023
  2. Just_Lukas

    Just_Lukas

    Joined:
    Feb 9, 2019
    Posts:
    34
    Chris_Webb likes this.
  3. ShidaPenns

    ShidaPenns

    Joined:
    May 9, 2013
    Posts:
    11
    It might be easy for you, but for me at the time (almost complete beginner) that was not enough info to know how to convert it in code. But, in any case, let me have the tiny victory, I don't have many of them. :p