Search Unity

"Failed to apply requested ExclusiveFullScreen resolution... will try again" (non-native resolution)

Discussion in 'Scripting' started by Wikzo-DK, Aug 5, 2019.

  1. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    When trying to set the game to ExclusiveFullScreen mode, if the resolution is not native to the monitor, the game tries to set the mode but fails.

    In the out_log.txt it writes:
    "Failed to apply requested ExclusiveFullScreen resolution (720x480)...will try again"
    . But when trying to set the resolution back to native 1920x1080, it won't set resolution and full screen mode correctly. It looks like it's stuck with the old non-native resolution.

    Here's a video of the behavior (Windows executable):
     
    Ignacii likes this.
  2. Wikzo-DK

    Wikzo-DK

    Joined:
    Sep 6, 2012
    Posts:
    83
    Here is the code I'm using:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections.Generic;
    4.  
    5. public class ResolutionManager : MonoBehaviour
    6. {
    7.     public Dropdown ScreenResolutionDropdown;
    8.     public Dropdown FullScreenModeDropdown;
    9.  
    10.     private string[] FULLSCREEN_MODE_NAMES = { "Exclusive FullScreen", "Fullscreen Window", "Windowed" };
    11.  
    12.     private void Start()
    13.     {
    14.         Setup();
    15.     }
    16.  
    17.     private void OnGUI()
    18.     {
    19.         GUI.Label(new Rect(10, 10, 500, 500), Screen.currentResolution.ToString());
    20.     }
    21.  
    22.     private void Setup()
    23.     {
    24.         ScreenResolutionDropdown.AddOptions(GetResolutionNames());
    25.         FullScreenModeDropdown.AddOptions(new List<string>(FULLSCREEN_MODE_NAMES));
    26.  
    27.         ScreenResolutionDropdown.onValueChanged.AddListener(SetScreenResolution);
    28.         FullScreenModeDropdown.onValueChanged.AddListener(SetFullScreenMode);
    29.     }
    30.     private List<string> GetResolutionNames()
    31.     {
    32.         List<string> resolutions = new List<string>(Screen.resolutions.Length);
    33.  
    34.         for (int i = 0; i < Screen.resolutions.Length; i++)
    35.             resolutions.Add($"{Screen.resolutions[i].width}x{Screen.resolutions[i].height} ({Screen.resolutions[i].refreshRate} Hz)");
    36.  
    37.         return resolutions;
    38.     }
    39.  
    40.     private void SetScreenResolution(int value)
    41.     {
    42.         ScreenResolutionDropdown.value = value;
    43.  
    44.         if (Screen.currentResolution.width != Screen.resolutions[value].width &&
    45.             Screen.currentResolution.height != Screen.resolutions[value].height)
    46.         {
    47.             Screen.SetResolution(Screen.resolutions[value].width, Screen.resolutions[value].height, true);
    48.             Debug.Log($"Setting resolution: {Screen.resolutions[value].width} x {Screen.resolutions[value].height}");
    49.         }
    50.     }
    51.  
    52.     private void SetFullScreenMode(int value)
    53.     {
    54.         FullScreenModeDropdown.value = value;
    55.  
    56.         // don't set the mode to the same twice
    57.         if (value == 0 && Screen.fullScreenMode != FullScreenMode.ExclusiveFullScreen)
    58.         {
    59.             Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
    60.             Debug.Log($"Setting fullscreenMode: ExclusiveFullScreen");
    61.         }
    62.         else if (value == 1 && Screen.fullScreenMode != FullScreenMode.FullScreenWindow)
    63.         {
    64.             Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
    65.             Debug.Log($"Setting fullscreenMode: FullScreenWindow");
    66.         }
    67.         else if (value == 2 && Screen.fullScreenMode != FullScreenMode.MaximizedWindow)
    68.         {
    69.             Screen.fullScreenMode = FullScreenMode.MaximizedWindow;
    70.             Debug.Log($"Setting fullscreenMode: MaximizedWindow");
    71.         }
    72.         else if (value == 3 && Screen.fullScreenMode != FullScreenMode.Windowed)
    73.         {
    74.             Screen.fullScreenMode = FullScreenMode.Windowed;
    75.             Debug.Log($"Setting fullscreenMode: Windowed");
    76.         }
    77.     }
    78. }
    79.