Search Issue Tracker

By Design

Votes

0

Found in

2017.4.0f1

2018.3.0a1

2018.4.0f1

2019.1.0a1

2019.1.1f1

2019.2.0a1

2019.3.0a1

Issue ID

1171856

Regression

No

Selecting constant Physical Size in Editor to set up a UI does not match when viewed on the Device because of the Pixel Density

uGUI

-

To reproduce:

1. Download attached "ConstantPhysicalSizeTest.zip" project and open in Unity
2. Open "SampleScene" scene
3. Set platform to iOS
4. In Game Window select iPhone X or other resolution
5. Notice that there is part of the Scene visible
6. Build for iOS
7. Deploy the Xcode project to the iOS device

Expected result: When App is launched you same behavior as in Editor
Actual result: When App is launched you will see that the screen is fully white

Notes:
- This issue happens on iOS, Android and Standalone with External Monitor
- Images for reference are attached in Comments section

Tested with:
- iPad Mini 4, iOS: 11.4.1 - Reproduced
- iPhone 6s Plus, iOS: 11.4.1 - Reproduced
- iPhone 8, iOS: 11.0 - Not Reproduced
- iPhone 8 Plus, iOS: 12.0 - Reproduced
- iPhone XR, iOS: 13.0 - Reproduced
- iPad Pro, iOS: 13.0- Not Reproduced
- VLNQA00230, Oneplus OnePlus6T (ONEPLUS A6013), Android 9, CPU: Snapdragon 845 SDM845, GPU: Adreno (TM) 630 - Reproduced
- VLNQA00006, Samsung Galaxy S7 (SM-G930F), Android 8.0.0, CPU: Exynos 8 Octa 8890, GPU: Mali-T880 - Reproduced
- VLNQA00277, Asus ROG Phone (ASUS_Z01QD), Android 8.1.0, CPU: Snapdragon 845 SDM845, GPU: Adreno (TM) 630 - Reproduced

Reproduced on Unity 2017.4.0f1, 2017.4.29f1, 2018.3.14f1, 2018.4.5f1, 2019.1.11f1, 2019.2.0b10 and 2019.3.0a10

  1. Resolution Note:

    Unfortunately, this is not going to be addressed any time soon.

    The issue is that the different resolutions available in the game view don't have any concept of DPI, and just set the resolution and aspect ratio for test purposes. While iOS devices are quite well defined, the Android devices, for example, are not, and there's currently no mechanism or API to make those available to the engine code from the Editor, and if we were to do that, we'd need to reconsider how various other parts of Unity (e.g. 2D) would also be affected and need corresponding changes.

    There are plans in the works to revamp the game view experience to make a more accurate simulation of how the game will look on device in future, but that's a significant new feature that won't be considered as a fix for backporting, unfortunately.

    The good news is that the CanvasScaler (and lots of the UI code) is available as source code inside Unity, and you can make the necessary changes to override the DPI yourself while in the Editor, to get a better idea of how things will look on device. Look in Unity.app/Contents/Resources/PackageManager/BuiltInPackages/com.unity.ugui

    com.unity.ugui/Runtime/UI/Core/Layout/CanvasScaler.cs has the constant physical size method, so you can override the behaviour there (using #if UNITY_EDITOR), and if you wanted, you could modify CanvasScalerEditor.cs to make this available in the editor for convenience.

    If you override 'currentDpi' in HandleConstantPhysicalSize() to match the device, the physical size will be 'wrong' in the editor (i.e. a 3cm x 3cm box will not necessarily be that size), but relative to the device resolution/game view size everything should be in proportion.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.