- Home /
Resolution Switch In Game Not Working Properly
I am trying to change the resolution in my game.
I want may game to start on a given resolution defined in Script and after that as per user input, But when i do that my screen just go black and nothing happen a prat from the size of my windowed game changes. I have been searching for this but i am not been able to find a solution for what i am experiencing, everything just stuck and i dose not move at all
This is the code i am using
This is where my resolution is being set on play
void Awake()
{
resolutionPopup.value = "1024x768";
SetResolution("1024x768", false);
graphicsPopup.value = "Fantastic";
SetQuality(5);
}
this is where It gets the supported resolutions and add them to my popup window
void Start () {
GetRes();
GetQuality();
NumberOfMonitors();
Debug.Log("Start");
}
this is where i am getting all suported resolutions of monitor
void GetRes()
{
Resolution[] resolutions = Screen.resolutions;
foreach (Resolution res in resolutions)
{
string resolution = res.width.ToString() + "x" + res.height.ToString();
SetDropDowmResolution(resolution);
}
}
this is the method which sets the resolution in to popup
void SetDropDowmResolution(string res)
{
resolutionPopup.items.Add(res);
}
this is where my selected resolution is being set
void SetResolution(string res, bool fullscreen)
{
string[] resBreak = res.Split('x');
Vector2 resV2 = new Vector2(Int32.Parse(resBreak[0]), Int32.Parse(resBreak[1]));
Screen.SetResolution((int)resV2.x, (int)resV2.y, fullscreen);
}
i am using Set Resolution Method GUI button Plz look into this matter as i am unable to solve it... Thanks
Answer by Naphier · May 13, 2016 at 09:42 AM
Does the same thing happen if you set the resolution in the player settings, but then later try to change it via code? It shouldn't matter, but maybe it does and maybe you need to set the supported orientations. I use this method in my Mobile Store Screenshot Helper asset that does this, I just built it with Unit 5.3.4p5 and it works 100%.
So I can only assume that there's an error in your code (I'd check those values you're actually setting the resolution to) or it's some conflict with the Player Settings. Attaching screencaps of mine in case it helps.
Thanks Naphier but i have unity 5.2.1f1 pro and i have cross checked my player settings from your images but i have noting which is in common so the issue stands
Can u check my code whether it has a problem or not
I see no immediate issues with your code. I can only suggest that you do some debugging of the following method:
void SetResolution(string res, bool fullscreen)
{
string[] resBreak = res.Split('x');
Vector2 resV2 = new Vector2(Int32.Parse(resBreak[0]), Int32.Parse(resBreak[1]));
Screen.SetResolution((int)resV2.x, (int)resV2.y, fullscreen);
}
One item that is unnecessary is the vector2. You're creating a new vector2 with parsed ints then casting the x & y of the vector2 back to ints. That shouldn't be the problem, but it's unnecessary. You need to put in a debug statement here to see what's really being passed to SetResolution.
Like I said, SetResolution works perfectly for me so it's either your code (which you'll need to deter$$anonymous$$e the errors by debugging) or it's something to do with your Player settings (which can be deter$$anonymous$$ed by taking your code to a new test project). It's also possible that you're using the GUI incorrectly, which we can only guess about because we can't see your hierarchy and button events.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
how to make my game for all screen please ? 1 Answer
Changing screen resolution is cutting the very edge of my screen off 1 Answer
Flip over an object (smooth transition) 3 Answers