✅ 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
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);
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 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!
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?
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!
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?)
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 } }
thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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.
@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.
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?
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.
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.
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
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.
✅ 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
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);
}
}
👈
To fix the obsolete problem: change the line 20 to currentRefreshRate = (float)Screen.currentResolution.refreshRateRatio.value;.
Thanks for this, the listings of all refresh rates was always so cluttering and this fixed that!
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 !
Thanks 😀
Thanks for this tutorial! You helped me to fix our resolution system ^^
Quick and easy to follow thanks!
Incredibly simple tutorial and well written code
Thanks ❤️
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);
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.
Nice one, thanks😊
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.
Thanks!
This will show resolution of the monitor where you open the game.
@@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!
Thanks man
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?
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!
Thank you for the tutorial! It works.
You're welcome! :D
Hi there, thank you for this, how do I implement Windowed checkbox?
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?)
I have the same issue
I found the fix, its because i had named my script "Resolution". I changed it smth else and it was solved
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
}
}
Thanks a lot, this helps with the issue of repeated resolutions :D
For some mine works in the editor only and not in the build, i followed step by step
Thank you!!!
Excelente muchas gracias
That helped a lot, thanks buddy
Idk why, but it shows every resolution except my highest one 1920x1080 (the one I actually run on). it shows 1650x1050 being the highest.
Maybe is late but i think it could be the filter by refresh rate.
Is that in the editor? That's the size of the resolution when running from there. Try running a build
thank you so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
excellent tutorial, clearly explained
Thanks 🙂
Почему у меня такая ошибка?
Cannot convert source type 'UnityEngine.RefreshRate' to target type 'float'
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.
I'm not sure that this works for phones.
Why does mine glitch on top of each other
everything is the same but still dont work
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?
@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.
@@TheGamingDelphox thank you
If you replace it the "currentResolutionIndex" becomes useless. It works perfectly fine for me. I am using a Playerprefs.
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?
not working :/
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.
Ok but how to use it in build
Use the same code as in the tutorial
@@RootGames how to make it change actual resolution
@@pankulas Don't understand you. It actually changes the resolution in the build.
non funziona neanche questo😔
hi i need the code in Reply
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.
@@RootGames thank you sir for the advice
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
Well this sucks if you dont want to use Dropdowns.
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.
@@RootGames I been trying for 2 weeks now. I am failing badly.
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
obsolet
change the line 20 to currentRefreshRate = (float)Screen.currentResolution.refreshRateRatio.value;
SLOW DOWN
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.
Skill issue