How to Change Unity screen size on Windows 10 Build

Hello,
In windows 10 they added a full functional window resize for windows store apps. My game content is designed for aspect ratio less then 16/9 and larger then 4/3. How can i set Unity Screen size when window scaled to unsupported values? Screen.SetResolution does not work on Windows. And when I tried to change the SwapChainPanel width and height it worked, but then, when i changed window size, unity input was disabled, i was unable to click anything. How can i solve this problem?

1 Like

What do you mean Screen.SetResolution does not work? Granted it wont resize the window, but setting resolution should work.

It work, but not as expected, I found error in my code…

OK, now I understand how SetResolution works. It’s only set screen proportions on the current window size, and the picture is stretches to the whole window.

But I need to set a Screen size and if window is too narrow, there will be empty space on top and bottom. I can achieve this by setting DXSwapChainPanel width and heigth.

But when I did that, Unity incorrectly process mouseInput, looks like all colliders are displaced. And I don’t know how to return a DXSwapChainPanel binding to window width and height, when window is resized back to supported resolution. Can you help me with that? Or any advise about what else I can try?

After resizing DXSwapChainPanel call UpdateWindowSize() on AppCallbacks.

I can’t find UpdateWindowSize() method nor in AppCallbacks nor in AppCallbacks.instance. Please prompt me a namespace or class where it located. Btw I’m buld windows store 8.1 app and run it on windows 10.

Unity is listening to DXSwapChainPanel SizeChanged event, but it’s triggered only when you change ActualHeight and ActualWidth properties… Could you try setting those instead?

I wish I could, but they are read only((

By the way, did you try playing with Unity - Scripting API: Camera.pixelRect ? By querying Screen.width, Screen.height, you can decide what values to set.

I have a complicated interface with 2D and 3D cameras in every scene. So it’s a hard way . For now I just made a dummy XAML control with an image with game logo on black screen and a message - Incorrect window size, and show it on top of everything when window in unsupported aspect.

We have same problem here…

Vlad, can you share the code you’re using to detect the wrong screen sizes and letting user know.
My game is also support 16/9 to 4/3, and I’m also looking for solution, thanks

It’s quite simple

DummyControl dummy;
float narrowestAspect = 4f / 3f;
float widestAspect = 1366f / 768f; //windows surface
private WindowSizeChangedEventHandler onWrongResolutiionHandler;

void SetWrongResolutionHandler()
{
        onWrongResolutiionHandler = new WindowSizeChangedEventHandler((o, e) =>
        {
            if (DXSwapChainPanel != null)
            {
                float aspectRatio = (float)Window.Current.Bounds.Width / (float)Window.Current.Bounds.Height;
                bool isSupportedAspect = true;
                if (aspectRatio < narrowestAspect || aspectRatio > widestAspect)
                {
                    isSupportedAspect = false;
                }
                if (isSupportedAspect)
                {
                    if (dummy != null)
                    {
                        DXSwapChainPanel.Children.Remove(dummy);
                        dummy = null;
                    }
                }
                else
                {
                    if (dummy == null)
                    {
                        dummy = new DummyControl();
                        DXSwapChainPanel.Children.Add(dummy);
                    }
                }
            }
        });
        Window.Current.SizeChanged += onWrongResolutiionHandler;
}
1 Like

Perfect ! thanks

Hi Vladrybak

We have the same problem here, and are looking for the same solution.

Did you manage to sort it?

How do you get a pointer to DXSwapChainPanel?

Many thanks

An alternative solution (Unity, call in void Update() ):

        float aspect_ratio = (float)Screen.width / (float)Screen.height;

        if (aspect_ratio < (4f/3f) || aspect_ratio > (16f/9f))
        {
            incorrect_window_size_text.SetActive(true);
        }
        else
        {
            incorrect_window_size_text.SetActive(false);
        }

Did anyone ever find a solution? I just get black boxes on top and bottom when the window is resized instead of a consistant screen size. I am getting so fustrated trying to find a fix. This problem seems to only be with UWP.

Can you post a screenshot and code you’re using?