Unity: Resolution Dropdown

Поделиться
HTML-код
  • Опубликовано: 15 ноя 2024

Комментарии • 72

  • @RootGames
    @RootGames  Год назад

    ✅ Get my courses with discount:
    👉 Unity 2D Master: www.udemy.com/course/unity2dmaster/?couponCode=2D-MASTER
    👉 Unity Mobile Course: www.udemy.com/course/unitymobilecourse/?couponCode=MOBILE
    👉 Unity Input System with Rebinding: www.udemy.com/course/unity-input-system-rebind/?couponCode=UNITY-INPUT

  • @turkmitolojioyunu
    @turkmitolojioyunu 4 месяца назад +12

    The correct code; 👉 using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using TMPro;
    public class SettingsResolution : MonoBehaviour
    {
    [SerializeField] private TMP_Dropdown resolutionDropdown;
    private Resolution[] resolutions;
    private List filteredResolutions;
    private float currentRefreshRate;
    private int currentResolutionIndex = 0;
    void Start()
    {
    resolutions = Screen.resolutions;
    filteredResolutions = new List();
    resolutionDropdown.ClearOptions();
    currentRefreshRate = (float)Screen.currentResolution.refreshRateRatio.value;
    for (int i = 0; i < resolutions.Length; i++)
    {
    if ((float)resolutions[i].refreshRateRatio.value == currentRefreshRate)
    {
    filteredResolutions.Add(resolutions[i]);
    }
    }
    filteredResolutions.Sort((a, b) => {
    if (a.width != b.width)
    return b.width.CompareTo(a.width);
    else
    return b.height.CompareTo(a.height);
    });
    List options = new List();
    for (int i = 0; i < filteredResolutions.Count; i++)
    {
    string resolutionOption = filteredResolutions[i].width + "x" + filteredResolutions[i].height + " " + filteredResolutions[i].refreshRateRatio.value.ToString("0.##") + " Hz"; // Ondalık basamak sınırlandı
    options.Add(resolutionOption);
    if (filteredResolutions[i].width == Screen.width && filteredResolutions[i].height == Screen.height && (float)filteredResolutions[i].refreshRateRatio.value == currentRefreshRate) // double'dan float'a dönüştürüldü
    {
    currentResolutionIndex = i;
    }
    }
    resolutionDropdown.AddOptions(options);
    resolutionDropdown.value = currentResolutionIndex = 0;
    resolutionDropdown.RefreshShownValue();
    SetResolution(currentResolutionIndex);
    }
    public void SetResolution(int resolutionIndex)
    {
    Resolution resolution = filteredResolutions[resolutionIndex];
    Screen.SetResolution(resolution.width, resolution.height, true);
    }
    }
    👈

  • @gabrielandraderosa8622
    @gabrielandraderosa8622 7 месяцев назад +21

    To fix the obsolete problem: change the line 20 to currentRefreshRate = (float)Screen.currentResolution.refreshRateRatio.value;.

  • @TripalYT
    @TripalYT 2 года назад +6

    Thanks for this, the listings of all refresh rates was always so cluttering and this fixed that!

  • @jozsefacs2224
    @jozsefacs2224 2 года назад +4

    Thankyou for the good tutorial from al of the tutorials this is the only one i can follow easy haha. Keep up the good work !

  • @rodriferg
    @rodriferg 10 месяцев назад +1

    Thanks for this tutorial! You helped me to fix our resolution system ^^

  • @madmanga64
    @madmanga64 Год назад +2

    Quick and easy to follow thanks!

  • @Ocer.
    @Ocer. Год назад +1

    Incredibly simple tutorial and well written code

  • @ShidaPenns
    @ShidaPenns Год назад +3

    Okay, with ChatGPT's help I finally figured out how to convert a refresh rate int, like 60, to the RefreshRate type it's saying you need for the fourth SetResolution argument. I'm a beginner so I'm proud of this. 😂 (ChatGPT was helpful in the end but holy crap did it give me a lot of wrong answers.)
    rRate is my refresh rate int, here. And width and height are the resolution sizes, naturally.
    // create a new RefreshRate instance
    RefreshRate refreshRate = new RefreshRate();
    // set the numerator and denominator properties separately
    refreshRate.numerator = (uint)rRate;
    refreshRate.denominator = 1;
    // Set the display resolution to the selected resolution and refresh rate
    Screen.SetResolution(width, height, FullScreenMode.ExclusiveFullScreen, refreshRate);

  • @dmitrycherkashin
    @dmitrycherkashin 6 месяцев назад

    set the variable "currentRefreshRate" to int, not a float and you do not the get any bugs with resolutions in dropdown. Sry for my english.

  • @castlecodersltd
    @castlecodersltd 5 месяцев назад +1

    Nice one, thanks😊

  • @vistitol
    @vistitol 2 года назад +2

    Hello.
    Good tutorial but i have a question, what happen if you hav more than one monitor??? This method is shoings the Resolution of the principal monitor or the Resolution of the monitor where the game is playing???
    Thanks.

    • @RootGames
      @RootGames  2 года назад

      Thanks!
      This will show resolution of the monitor where you open the game.

    • @ThatRazzy
      @ThatRazzy Год назад

      @@RootGames Hi there, thank you for the great tutorial. So I'm having a similar issue to the one @vistitol mentioned. No matter which monitor I open the game on, I believe the filtered resolutions list only includes the resolutions/framerates of my main display. My main display is at 60hz and my secondary is at 144hz. Because the list of filtered resolutions only includes those of my main display (I'm assuming), launching the game on my second monitor causes the following error:
      ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
      Parameter name: index
      Do you have any suggestions on how to fix this/populate the list with the resolutions/framerates of all connected displays? Thank you in advance!

  • @Kaldrin
    @Kaldrin 6 месяцев назад +2

    Thanks man

  • @amees89
    @amees89 Год назад +2

    Hi nice Video!
    I have a problem tho, the Dropdown menu wont change my Resolution. Its stuck at 600x480 or something and even if I change it to 1920x1080 its still not changing.
    do you have a solution?

    • @llibertii
      @llibertii Год назад +1

      Take a closer look at the line 35 of the tutorial you probably didn't change the resoltutions to filteredResolutions.
      I had the same issue since instead of rewritting the entire script I just tried to fix the one I had and forgot to change that but luckily I managed to figure that out.
      Hope that helps!

  • @cristiangenete8734
    @cristiangenete8734 Год назад +1

    Thank you for the tutorial! It works.

  • @pushthebutton4602
    @pushthebutton4602 Год назад

    Hi there, thank you for this, how do I implement Windowed checkbox?

  • @nexotin
    @nexotin Год назад +2

    I dont know how to fix the Error...
    Assets\Scripts\Resolution.cs(51,53): error CS1061: 'Resolution' does not contain a definition for 'height' and no accessible extension method 'height' accepting a first argument of type 'Resolution' could be found (are you missing a using directive or an assembly reference?)

    • @mandrutalol3631
      @mandrutalol3631 7 месяцев назад

      I have the same issue

    • @mandrutalol3631
      @mandrutalol3631 7 месяцев назад

      I found the fix, its because i had named my script "Resolution". I changed it smth else and it was solved

  • @TegridyMadeGames
    @TegridyMadeGames Год назад +3

    Had an issue where it would make each resolution 5 times after building, i guess for variable refresh rates (which i really did NOT want lol)
    Heres a fix if anyone need it, checks for duplicate resolutions sizes:
    using System.Linq;
    //this first line is a reference of where to add it in the script
    currentRefreshRate = Screen.currentResolution.refreshRate;
    //this is the actual loop check
    for (int i = 0; i < resolutions.Length; i++)
    {
    if (!filteredResolutions.Any(x => x.width == resolutions[i].width && x.height == resolutions[i].height)) //check if resolution already exists in list
    {
    filteredResolutions.Add(resolutions[i]); //add resolution to list if it doesn't exist yet
    }
    }

    • @jaguar1822
      @jaguar1822 Год назад

      Thanks a lot, this helps with the issue of repeated resolutions :D

  • @unknxwn7381
    @unknxwn7381 11 месяцев назад

    For some mine works in the editor only and not in the build, i followed step by step

  • @volverte7908
    @volverte7908 Год назад +1

    Thank you!!!

  • @felipeagudelo76
    @felipeagudelo76 Год назад +2

    Excelente muchas gracias

  • @acarius4747
    @acarius4747 Год назад +1

    That helped a lot, thanks buddy

  • @ZPanda13
    @ZPanda13 Год назад +2

    Idk why, but it shows every resolution except my highest one 1920x1080 (the one I actually run on). it shows 1650x1050 being the highest.

    • @credormk5770
      @credormk5770 11 месяцев назад

      Maybe is late but i think it could be the filter by refresh rate.

    • @castlecodersltd
      @castlecodersltd 5 месяцев назад

      Is that in the editor? That's the size of the resolution when running from there. Try running a build

  • @TegridyMadeGames
    @TegridyMadeGames Год назад +2

    thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @briangular2115
    @briangular2115 Год назад +1

    excellent tutorial, clearly explained

  • @Xitman239
    @Xitman239 Год назад

    Почему у меня такая ошибка?
    Cannot convert source type 'UnityEngine.RefreshRate' to target type 'float'

  • @alice0067
    @alice0067 Год назад

    i am having a problem with the resolution settings, its working fine in my editor but when i run it in my phone, i can see only one resolution which is the current resolution of my screen. I cant see any other resolutions from that dropdown.

    • @RootGames
      @RootGames  Год назад

      I'm not sure that this works for phones.

  • @Eastyoffutt
    @Eastyoffutt Год назад

    Why does mine glitch on top of each other

  • @Markleap
    @Markleap Год назад

    everything is the same but still dont work

  • @TheGamingDelphox
    @TheGamingDelphox Год назад

    The dropdown box always starts at 640x480 60hz (The First Option) even though the build is actually in 1920 x 1080 60hz. Is there a way to fix this?

    • @TheGamingDelphox
      @TheGamingDelphox Год назад +5

      @voxel zombie I think I fixed it. I replaced "resolutionDropdown.value = currentResolutionIndex;" with "resolutionDropdown.value = Mathf.Max(options.Count);". currentResolutionIndex had a value of 0, setting the dropdown to the smallest resolution, the new line of code sets the value to the highest amount based on the number of options present.

    • @Simulatech
      @Simulatech Год назад

      @@TheGamingDelphox thank you

    • @sundee7371
      @sundee7371 7 месяцев назад

      If you replace it the "currentResolutionIndex" becomes useless. It works perfectly fine for me. I am using a Playerprefs.

  • @Armaan8014
    @Armaan8014 Год назад

    What if we want the text to be a label/TMPro text instead of a dropdown like this video? ruclips.net/video/-Zwk-C0BtEU/видео.html
    The resolution.AddOptions(options) etc parts dont work - what could be the substitute then?

  • @maximtarna6669
    @maximtarna6669 2 года назад

    not working :/

    • @RootGames
      @RootGames  2 года назад

      It works. Double check your code. Also, try setting the "currentRefreshRate" variable manually, for example, set it to 60 and you'll only get resolutions with that refresh rate. As I said in the video, you need to make a build to test it correctly.

  • @pankulas
    @pankulas Год назад

    Ok but how to use it in build

    • @RootGames
      @RootGames  Год назад

      Use the same code as in the tutorial

    • @pankulas
      @pankulas Год назад

      @@RootGames how to make it change actual resolution

    • @RootGames
      @RootGames  Год назад +1

      @@pankulas Don't understand you. It actually changes the resolution in the build.

  • @puriceful
    @puriceful Год назад

    non funziona neanche questo😔

  • @ziadmouad5889
    @ziadmouad5889 Год назад

    hi i need the code in Reply

    • @RootGames
      @RootGames  Год назад +2

      I don't have the code to copy-paste it but you will learn more if you follow the tutorial and try to write it step by step. Trust me, avoid copy paste without understanding the logic behind the code.

    • @ziadmouad5889
      @ziadmouad5889 Год назад +3

      ​@@RootGames thank you sir for the advice

  • @elijahbernard3113
    @elijahbernard3113 2 месяца назад

    I am getting this error: ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    Any help would be appreciated

  • @talismanskulls2857
    @talismanskulls2857 Год назад +1

    Well this sucks if you dont want to use Dropdowns.

    • @RootGames
      @RootGames  Год назад

      Well you can modify the code and use it in other ways. You can go through elements by clicking left/right buttons. Play a little bit with the code.

    • @talismanskulls2857
      @talismanskulls2857 Год назад

      @@RootGames I been trying for 2 weeks now. I am failing badly.

  • @Mr.Legend360
    @Mr.Legend360 9 месяцев назад

    can you provide me script plz i cant see because font size is too small plz bro i will be very thanksful to you plz

  • @Jelandro_sander
    @Jelandro_sander 8 месяцев назад +2

    obsolet

    • @gabrielandraderosa8622
      @gabrielandraderosa8622 7 месяцев назад

      change the line 20 to currentRefreshRate = (float)Screen.currentResolution.refreshRateRatio.value;

  • @legionofregion8825
    @legionofregion8825 6 месяцев назад

    SLOW DOWN

  • @limasapenas
    @limasapenas 9 месяцев назад

    Thanks for the help, my only criticism is that you overestimates the viewer intelligence, so I think you should talk about the minor things you did that you speed up, just so I don't need to go back to see exactly what you did, but besides that, it's a great tutorial.

    • @uluc0
      @uluc0 5 месяцев назад

      Skill issue