Hello,
TL;DR : Could someone explain clearly the relationship between Screen and Display? And, how do we change the main display at runtime?
A word on my setup first :
- Windows 10 x64 creator update
- Unity 5.6.1p2
- Two monitors
- monitor 1 is a 1920x1200 16/10 in portrait mode (so, effectively, 1200x1920 in resolution)
- monitor 2 is a 1920x1080 16/9 in landscape mode and set as primary monitor
Our game only runs in 16/9. Recently, I added a custom canvas scaler and some black borders so that the game can run with any resolution. I based all my computations on Display.main.renderingWidth/Height. All was fine in the editor, I could set any kind of weird resolution like with those 32/9 ultra wide samsung monitors and the rendering was done centered, in 16/9, with black borders, everything fine.
Then I did a build and everything became very weird. First, I noticed that Display.main.renderingWidth/Height was always giving me 1920x1080. Then, at some point, maybe when I started playing around with resolutions in our in-game menu that uses Screen.SetResolution, Unity started deciding that the monitor 1 was the primary monitor and would only render to it. If I disabled full screen and changed resolution, it would move the window always to the center of monitor 1. Our in-game settings menu displays the resolution available in Screen.resolutions which are the ones from monitor 1 so it was the correct resolutions, but I would prefer playing on the main monitor, the horizontal one…
Then I plugged in the debugger and saw this :

As you can see, the main display (0) has the resolution of monitor 2 but in portrait instead of landscape and display 1 has the resolution of monitor 1 but in landscape instead of portrait.
This is all very weird and feel like bugs. So my questions are : am I understanding all this? How do we switch the main monitor at runtime? The Screen API has nothing for this and the Display API only enables creating new displays, not disabling the main one to switch it over the second one…
EDIT: btw

EDIT2: btw
I switched my code to use Screen.resolutions instead but that screws up in the editor. So I ended up using this piece of weird stuff… It works fine in builds, fullscreen or not
#if UNITY_EDITOR
float width = Display.main.renderingWidth;
float height = Display.main.renderingHeight;
#else
float width = Screen.currentResolution.width;
float height = Screen.currentResolution.height;
#endif
float screenAspect = width / height;
EDIT3: wtf ? ![]()
PlayerPrefs.SetInt("UnitySelectMonitor", 0); // Select monitor
PlayerPrefs.SetInt("UnitySelectMonitor", 1); // Select monitor 2