Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to Change Unity screen size on Windows 10 Build

Discussion in 'Windows' started by vladrybak, Oct 1, 2015.

  1. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    108
    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?
     
    AbgaryanFX likes this.
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,642
    What do you mean Screen.SetResolution does not work? Granted it wont resize the window, but setting resolution should work.
     
  3. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    108
    It work, but not as expected, I found error in my code...
     
  4. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    108
    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?
     
  5. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,642
    After resizing DXSwapChainPanel call UpdateWindowSize() on AppCallbacks.
     
  6. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    108
    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.
     
  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
    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?
     
  8. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    108
    I wish I could, but they are read only((
     
  9. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,672
  10. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    108
    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.
     
  11. AbgaryanFX

    AbgaryanFX

    Joined:
    Jan 9, 2010
    Posts:
    167
    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
     
  12. vladrybak

    vladrybak

    Joined:
    Aug 30, 2013
    Posts:
    108
    It's quite simple
    Code (CSharp):
    1.  
    2. DummyControl dummy;
    3. float narrowestAspect = 4f / 3f;
    4. float widestAspect = 1366f / 768f; //windows surface
    5. private WindowSizeChangedEventHandler onWrongResolutiionHandler;
    6.  
    7. void SetWrongResolutionHandler()
    8. {
    9.         onWrongResolutiionHandler = new WindowSizeChangedEventHandler((o, e) =>
    10.         {
    11.             if (DXSwapChainPanel != null)
    12.             {
    13.                 float aspectRatio = (float)Window.Current.Bounds.Width / (float)Window.Current.Bounds.Height;
    14.                 bool isSupportedAspect = true;
    15.                 if (aspectRatio < narrowestAspect || aspectRatio > widestAspect)
    16.                 {
    17.                     isSupportedAspect = false;
    18.                 }
    19.                 if (isSupportedAspect)
    20.                 {
    21.                     if (dummy != null)
    22.                     {
    23.                         DXSwapChainPanel.Children.Remove(dummy);
    24.                         dummy = null;
    25.                     }
    26.                 }
    27.                 else
    28.                 {
    29.                     if (dummy == null)
    30.                     {
    31.                         dummy = new DummyControl();
    32.                         DXSwapChainPanel.Children.Add(dummy);
    33.                     }
    34.                 }
    35.             }
    36.         });
    37.         Window.Current.SizeChanged += onWrongResolutiionHandler;
    38. }
    39.  
     
    AbgaryanFX likes this.
  13. AbgaryanFX

    AbgaryanFX

    Joined:
    Jan 9, 2010
    Posts:
    167
    Perfect ! thanks
     
  14. PixelSquad

    PixelSquad

    Joined:
    Sep 4, 2014
    Posts:
    114
    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
     
  15. Nolex

    Nolex

    Joined:
    Dec 10, 2010
    Posts:
    115
    An alternative solution (Unity, call in void Update() ):

    Code (CSharp):
    1.  
    2.         float aspect_ratio = (float)Screen.width / (float)Screen.height;
    3.  
    4.         if (aspect_ratio < (4f/3f) || aspect_ratio > (16f/9f))
    5.         {
    6.             incorrect_window_size_text.SetActive(true);
    7.         }
    8.         else
    9.         {
    10.             incorrect_window_size_text.SetActive(false);
    11.         }
     
  16. DemonGamesLab

    DemonGamesLab

    Joined:
    Nov 10, 2015
    Posts:
    9
    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.
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,507
    Can you post a screenshot and code you're using?