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):
1 Like
Here is the code I’m using:
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
public class ResolutionManager : MonoBehaviour
{
public Dropdown ScreenResolutionDropdown;
public Dropdown FullScreenModeDropdown;
private string[] FULLSCREEN_MODE_NAMES = { "Exclusive FullScreen", "Fullscreen Window", "Windowed" };
private void Start()
{
Setup();
}
private void OnGUI()
{
GUI.Label(new Rect(10, 10, 500, 500), Screen.currentResolution.ToString());
}
private void Setup()
{
ScreenResolutionDropdown.AddOptions(GetResolutionNames());
FullScreenModeDropdown.AddOptions(new List<string>(FULLSCREEN_MODE_NAMES));
ScreenResolutionDropdown.onValueChanged.AddListener(SetScreenResolution);
FullScreenModeDropdown.onValueChanged.AddListener(SetFullScreenMode);
}
private List<string> GetResolutionNames()
{
List<string> resolutions = new List<string>(Screen.resolutions.Length);
for (int i = 0; i < Screen.resolutions.Length; i++)
resolutions.Add($"{Screen.resolutions[i].width}x{Screen.resolutions[i].height} ({Screen.resolutions[i].refreshRate} Hz)");
return resolutions;
}
private void SetScreenResolution(int value)
{
ScreenResolutionDropdown.value = value;
if (Screen.currentResolution.width != Screen.resolutions[value].width &&
Screen.currentResolution.height != Screen.resolutions[value].height)
{
Screen.SetResolution(Screen.resolutions[value].width, Screen.resolutions[value].height, true);
Debug.Log($"Setting resolution: {Screen.resolutions[value].width} x {Screen.resolutions[value].height}");
}
}
private void SetFullScreenMode(int value)
{
FullScreenModeDropdown.value = value;
// don't set the mode to the same twice
if (value == 0 && Screen.fullScreenMode != FullScreenMode.ExclusiveFullScreen)
{
Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
Debug.Log($"Setting fullscreenMode: ExclusiveFullScreen");
}
else if (value == 1 && Screen.fullScreenMode != FullScreenMode.FullScreenWindow)
{
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
Debug.Log($"Setting fullscreenMode: FullScreenWindow");
}
else if (value == 2 && Screen.fullScreenMode != FullScreenMode.MaximizedWindow)
{
Screen.fullScreenMode = FullScreenMode.MaximizedWindow;
Debug.Log($"Setting fullscreenMode: MaximizedWindow");
}
else if (value == 3 && Screen.fullScreenMode != FullScreenMode.Windowed)
{
Screen.fullScreenMode = FullScreenMode.Windowed;
Debug.Log($"Setting fullscreenMode: Windowed");
}
}
}