Search Unity

UWP resolution and presentation (store rejects everything)

Discussion in 'Windows' started by MarcusTheMainMan, Oct 9, 2019.

  1. MarcusTheMainMan

    MarcusTheMainMan

    Joined:
    Nov 29, 2012
    Posts:
    218
    In project settings>resolution and presentation,
    You can set the width and height to 1920x1080. You can also have the supported aspect ratio set at only 16:9.

    However, in UWP, you don't have that. There is a default is full screen.

    Now here's the thing, if someone uses UWP and runs a game not in 16:9, then the outsides (left and right side of monitor) get cut off. Uploading to the Microsoft store and all of my games get rejected. All of the other OSes you can set it to 16:9, but not UWP in unity.

    So I was wondering how to fix this. The obvious guy would say make all of the games 4:3 aspect ratio. That might be a solution when starting out, but not after having everything done. Is there a way with UWP to force a 16:9 aspect ratio like windows EXE? or maybe force a window mode or something? The options just are not there in unity for UWP.


    In the unity manual
    file:///C:/Program%20Files/UnityInstalls/2019.2.8f1/Editor/Data/Documentation/en/Manual/class-PlayerSettingsWSA.html

    It says this but that is not an option.
    Default is Fullscreen Set the window to the full-screen native resolution of the display. Unity renders app content at the resolution set by script (or by user selection when the built application launches), but scales it to fill the window. When scaling, Unity adds black bars to the rendered output to match the aspect ratio
    The relationship of an image’s proportional dimensions, such as its width and height.
    See in Glossary chosen in the Player settings, so that the content isn’t stretched. This process is called letterboxing.
     

    Attached Files:

    • a.PNG
      a.PNG
      File size:
      24.6 KB
      Views:
      8
    • b.PNG
      b.PNG
      File size:
      14.1 KB
      Views:
      10
  2. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    78
    So, the simple response is: you're correct, this is missing functionality for UWP and it's something we've been thinking of addressing. However, the work item is currently low priority.

    The longer answer is: with Fullscreen in UWP, the app always runs in the OS display resolution regardless of what you set. If you do specify a different "Resolution" in Unity, Windows will just up/down scale or letterbox the output to match the native resolution and aspect ratio. UWP does not allow you to change the actual resolution as with WindowsStandalone, i.e. ExclusiveFullscreen mode.

    Since a scaled and/or letterbox output looks bad, you're better off leaving it in the native resolution and adapting the game's visual to match the screen size. Of course you can always change the output "Resolution" at runtime in scripts or set width/height in PlayerPrefs yourself if you really need this functionality.

    From our perspective, the inclusion of the Width/Height option is more useful for Windowed mode, allowing you to set the initial size of the Window when the app launches.
     
  3. MarcusTheMainMan

    MarcusTheMainMan

    Joined:
    Nov 29, 2012
    Posts:
    218
    1) It's not the resolution but the aspect ratio. Microsoft checks apps with 800x600 (4x3) for their store but pretty much all games use 1920x180 (16x9) now days. That's a lot of screen space just wasted.
    2) So if 'default is fullscreen' I checked, it just takes the current OS resolution. But if not checked, can it be forced to be 16x9?
    3) Letterbox looks fine. Most movies on TV use letterbox as the aspect ratio in the theatre is longer.
    4) What really annoys me about unity is that the resolution is saved to player prefs and the next time the game is run it uses that resolution. So If I run a game at 800x600, then the next time it will be run at 800x600. It doesn't matter that the resolution now is at 1920x1080. You have to go to the reg and delete it. For players, they will always have the lower resolution and wrong aspect ratio even after deleting the game and reinstalling it. They are not going to know this or how to do it.
     
  4. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    78
    So let me comment on each of these points:
    Yes, UWP apps are required to support 800x600 as the minimum display size but that doesn't mean the app has to always run like that. I don't know how this is check in Cert, but I suspect the app is launched onto an 800x600 display just to make sure it activates and displays properly.

    So, if you check "fullscreen" in the build settings and the app is forced to run on an 800x600 display, by default Unity will use that native resolution/aspect ratio (first time app is launched). If the app changes the aspect ratio after launch, e.g. 1920x1080, then letter boxes will automatically be added. This is actually performed by the Windows Compositor and not really by Unity.
    Yes, you can always change the display size at runtime via the UnityEngine.Screen APIs. For example you could create a simple "start-up" script with your first scene to force 16:9 aspect ratio:

    Code (CSharp):
    1. public class Example : MonoBehaviour
    2. {
    3.     void Start()
    4.     {
    5.         // Switch to Fullscreen 16:9 aspect ratio
    6.         UnityEngine.Screen.SetResolution(1920, 1080, true);
    7.     }
    8. }
    If you make this change at runtime, the setting will be saved to PlayerPrefs and the app will automatically start in this mode.
    Sure, for movies and video playback it's fine; I'm guessing this is your intent. However, IMO for gameplay itself I definitely don't want letterboxes and instead want the game to use my native aspect ratio.
    I agree this is annoying but it's also a useful for games that allow you to change your display resolution in the options menu. For example, I have a native 4K monitor but my graphics card cannot deliver 60FPS at that resolution, so I go into the in-game options and select 1080p instead. Now, I want the game to remember that setting the next time I launch it. So, saving display size in PlayerPrefs automatically satisfies this expectation.

    Sadly, this isn't way you always want (especially during development), and of course it doesn't really make sense for UWP since you cannot actually change the resolution. However, your app can always change the display to whatever aspect ratio you need at runtime.

    So, let's say you want your opening cinematic to be in 19x9, you could do something like this in you scripts:
    1. App launches in native resolution
    2. Save current native resolution
    3. Change to 16:9 aspect ratio
    3. Play cinematic
    4. Restore original resolution
    5. Display Title Screen or Main Menu

    I hope this is helpful.
     
  5. MarcusTheMainMan

    MarcusTheMainMan

    Joined:
    Nov 29, 2012
    Posts:
    218
    That was super helpful. Thanks.

    So- If I use this script to go to 1920x1080 in the bootstrapper scene, then what happens if the computer can not do 1920x1080? Will it go down to the next RESOLUTION or will it go down to the next same ASPECT RATIO? I really don't care about the resolution It's the aspect ratio that matters because of the game's onscreen graphics are outside the 4:3 ratio.

    Also, does any of the win32 'resolution and presentation' settings carry over to the UWP?
     
    Last edited: Oct 11, 2019
  6. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    78
    For UWP it shouldn't matter what "resolution" values you pass in for the SetResolution API. Since Windows will just scale the output; I don't think there's any "unsupported" values in UWP. For Win32, if SetResolution fails, then Unity will try to restore the previous width/height values, or if that's not possible, fall back to the native resolution.

    Still, to be safe, I'd recommend using the UnityEngine.Screen.Resolutions API (returns a list of supported resolutions) and simply find one from that list that has 16:9 aspect ratio. To be honest, you should be fine with 1920x1080.

    Win32 resolution and presentation settings should not carry over to UWP, as each platform should track settings separately. If you do see this occurring then let us know because that's a bug.
     
  7. MarcusTheMainMan

    MarcusTheMainMan

    Joined:
    Nov 29, 2012
    Posts:
    218
    Ok, so I'll do that.

    1 last question. If I have the full screen checked and then in the 1st scene do the 1920x1080 script above, then will it start full screen and then switch over to 1920x1080? The reason I'm asking is I just tested out your script and it starts up in 800x600 with a window then after the splash screen will go to 1920x1080 without a window. So if I just checkmark the start fullscreen then it should start without a window border? I want to get rid of the window and just have it go full screen.
     
  8. MarcusTheMainMan

    MarcusTheMainMan

    Joined:
    Nov 29, 2012
    Posts:
    218
    So here is another issue.
    - I put that code into the 1st scene in a project (changing it to Awake instead of Start).
    - Using UWP (after building in Visual Studio). Now, it starts the game and switches to full screen mode. Everything seems to work as planned.
    - BUUUT now the cursor arrow will now get detected to the right side of the screen. It's not just on the main menu but every where in the game. This happens in UWP.
    - You can move the mouse cursor anywhere, but on the right 1/4th side of the screen the onHover and click do not work for the buttons most of the time.
    - Looking at the screenshot, you can see the yellow line. When you move the arrow to the right of it, the hover no longer works. It'll work just to the left of the yellow line where the 'S' is.
    - When I take out the code above so it does not change the resolution in the 1st scene, the issue is no longer there. So it is the code that's doing this. I have tested this for UWP with and without your code.
    - In the editor (with UWP set up) it works fine.
    - It's when I run the game from a APPX build after making it run in visual studio that this issue pops up.
    - I have tested this in win32 with the code and the issue is not there. So it only happens in UWP.

    So maybe it's me, but this code in UWP has issues.

    My computer is older with a max of 1366x768 if that matters (not 1920x1080 mode).
     

    Attached Files:

    Last edited: Oct 12, 2019 at 10:03 PM
  9. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    78
    This is the "Build and Run" option, right? That's pretty bizarre for the issue to only repro with your VS build of the app, because "Build and Run" for UWP executes MSBuild from your VS installation and generates an APPX similar to VS.

    It sounds like the UI or mouse input isn't "seeing" the screen changes and isn't scaling the mouse coordinates appropriately. This may be a Unity bug which we'll need to investigate further, and so could you please file a bug report (from the Bug Reporter tool) for this issue?

    A couple follow-up questions:

    Are you using uGUI for your UI or some other framework?
    What "Build type" are you using: "D3D Project", "XAML Project" or "Executable Only"?
    Do you have multiple versions of VS installed and which version are you using?

    There's something different between the Editor and VS builds, I like to figure out what that difference is as a work-around for the bug.
     
  10. MarcusTheMainMan

    MarcusTheMainMan

    Joined:
    Nov 29, 2012
    Posts:
    218
    - In unity I built the UWP. I went to VS and built a master bundle. win32, win64 and arm32.
    - uGUI I guess. I'm just using a canvas with the UI buttons on top of them. Theses were created from the top menu bar in the unity editor.
    - I also have verified that there are no text elements in front of the buttons with raycast on. I just verified that this happens in UWP build but not win32 build. In the win32 build, the game works fine with the script above on or off.
    - I have not messed with the build type as I have no clue what they due. But it's set to D3Dproject.
    - Only 1 version of VS 2017. It's the one that came with unity. I got a new hard drive 2 months ago and had to reinstall everything including windows so all of that old crap is gone. Using unity 2019 latest version.
     

    Attached Files:

    • a.PNG
      a.PNG
      File size:
      115.5 KB
      Views:
      1
  11. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    78
    Thanks for the clarification. The issue is almost certainly a bug in the mouse coordinate scaling that occurs after changing the Screen mode, and so please submit a bug for this problem. I don't think this is a known issue.

    If you don't mind sharing a Unity project to this forum post that repros the problem (e.g. Google Drive, OneDrive, Dropbox, etc.) I might be able to find a work-around. It doesn't have to be your real project, but something simple that demonstrates the broken UWP behavior.
     
  12. MarcusTheMainMan

    MarcusTheMainMan

    Joined:
    Nov 29, 2012
    Posts:
    218
    I reported it:
    (Case 1191482) UWP resize-won't onhover or mouse click