Search code examples
unity-game-enginebuildresolution

Why don't I get the right resolution after I build the game in my in-built settings menu but inside Editor everything is fine? Unity


When I actually try the game inside Unity everything is fine. When I build the game and try it every resolution is shown twice and they are reversed(ex: 1920 x 1080 is 320 x 200, 1680 x 1050 is 320 x 240 and so on). I will give you my code here:

public Dropdown resolutiondropdown;
 Resolution[] resolutions;
 void Start()
 {
     resolutions = Screen.resolutions;
     resolutiondropdown.ClearOptions();
     int currentresolutionindex = 0;
     List<string> options = new List<string>();
     for(int i=resolutions.Length-1;i>=0;i--)
     {
         string option = resolutions[i].width + " x " + resolutions[i].height;
         options.Add(option);
         if (resolutions[i].width == Screen.width && resolutions[i].height == Screen.height)
             currentresolutionindex = i;
     }
     resolutiondropdown.AddOptions(options);
     resolutiondropdown.value = currentresolutionindex;
     resolutiondropdown.RefreshShownValue();
 }
 public void SetResolution(int resolutionindex)
 {
     Resolution resolution = resolutions[resolutionindex];
     Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
 }

And a screenshot I took: Settings menu


Solution

  • This dude implement resolution setting in this video, try it out: https://www.youtube.com/watch?v=YOaYQrN1oYQ

    So, I cant repeat your problem - your solution also works fine

    This it windows default build with your code:

    screenshot

    Try to check your 'Resolution and presentation' in Player settings

    This is source code of resolution list - unity just takes it from your pc:

    /// <summary>
    ///   <para>All full-screen resolutions supported by the monitor (Read Only).</para>
    /// </summary>
    public static extern Resolution[] resolutions { [FreeFunction("ScreenScripting::GetResolutions"), MethodImpl(MethodImplOptions.InternalCall)] get; }
    

    Thats why there is only one solution - manually check duplicates and remove it from the list