Screen.resolutions returns 640x480 in the build

I heard that it’s only supposed to do that in the editor, but it’s insisting that it do so in the build as well.
My test code is very very simple.

void OnGUI()
{
        GUI.Label(new Rect(10, 10, 300, 50), Screen.resolutions.ToString());
}

And yet, it always shows as empty, actually. Any attempts to use anything in the array always end up at 640x480.
I’m trying to code me a nice options menu, but I’m totally stuck now. Anyone have any ideas?

–IronDuke

Edit: Running this in the Unity editor will only return 640 x 480 @ 0hz. If you build and run the project then it will return the supported resolutions. I just tested and confirmed this.


Screen.resolutions is an array of resolution

Make the below change to see the contents of the first element inside the array.
Check Screen.resolutions Unity documentation for more details for other available resolutions.

 void OnGUI()
 {
         GUI.Label(new Rect(10, 10, 300, 50), Screen.resolutions[0].ToString());  //Added [0] to access first element in the array
 }

Yeah, I’ve been hacking at the problem for a while. The code above was a super-simplified version, always showing an annoyingly empty array in the top left on play. I tried it on older Unity versions, other projects, heck, other computers, but always the same, and always written from scratch.
When I try to access anything in the array, as in what you posted, it returns 640x480 @ 0hz. I’m assuming that’s because the array is completely empty and it’s having to create a resolution, which seems to be 640x480 by default.
I simply cannot figure out why the silly thing keeps returning empty. Did it work ok on your end?

Edit: I saw that when I was searching for a solution, but it acts the same whether it’s in the editor or in a build. Maybe there is something making it think the build is still the editor, I just don’t know.

–IronDuke