CanvasScaler creating incorrect scale due to incorrect screen size on iOS

Afternoon all,

The screen of my app, displays sometimes incorrect (too big), because the CanvasScaler that is attached to my Canvas is settings it’s scale incorrect. This does not happen in the editor but only on an physical iOS device (tested on iPhone X & iPad pro 2019 13").

After debugging the CanvasScaler, I found it it’s due to the UnityEngine.Screen.width returning an incorrect value.

namespace UnityEngine
{
  public sealed class Screen
  {
    /// <summary>
    ///   <para>The current width of the screen window in pixels (Read Only).</para>
    /// </summary>
    public static int width
    {
      get
      {
        return ShimManager.screenShim.width;
      }
    }
}

In a good run it returns :arrow_forward: screenSize “(2732.0, 2048.0)” UnityEngine.Vector2
In a bad run its :arrow_forward: screenSize “(1200.0, 900.0)” UnityEngine.Vector2

So why is the UnityEngine.Screen.width returning 1200 instead of 2732?
Anyone came across this issue or am I doing something wrong?

Best regards,

Ronald

what values does it return?

You can set the Game window in Unity to mock precise resolutions of these annoyingly-wide devices.

Also, don’t forget the safe area properties inside of Screen:

Also, it might be useful to encase parts of your UI in square-aspect-ratio (using AspectRatioFitter) containers, in order to precisely control text size.

** @Carpet_Head **
Thank you for your question.
In a good run it returns
Name Value Type
:arrow_forward: screenSize “(2732.0, 2048.0)” UnityEngine.Vector2
In a bad run its :
Name Value Type
:arrow_forward: screenSize “(1200.0, 900.0)” UnityEngine.Vector2

** @Kurt-Dekker **
Thank you, but the iPad Pro option inside the editor is correct regarding the resolution
And I am aware of the SafeArea, however the code I am referring too is inside Unity’s own namespace. CanvasScaler is from Unity and Screen is from Unity

FYI this has been resolved.

During loading of the scene, a monobehaviour was loaded that set the screen to 1200,900 …:face_with_spiral_eyes:.

Screen.SetResolution(1200, 9000, FullScreenMode.Windowed);

Probably some remnant of testing.

Thank you for your comments