Search Unity

Bug Device Simulator - Bogus values from Screen.width and Screen.safeArea

Discussion in 'Editor & General Support' started by bobbaluba, Jun 3, 2021.

  1. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    So I think this is a bug, but it's hard to tell, since it isn't really documented what will happen to Screen.width/height when a device rotates: https://docs.unity3d.com/ScriptReference/Screen-width.html

    I was trying to use a phone notch solution script and test it out with the device simulator, but it didn't work, the padding was all wrong, so I tried writing one myself, only to figure out that the values of Screen.width and safeArea seem wildly inconsistent.

    I had some issues with it a couple of months back, but that was only in Awake, and it worked if I had the simulator in a separate window. Now I can't seem to get straight answers no matter what/when I try. Often the screen size is in portrait, while the safeArea is in landscape, or the other way around, and one is sometimes 4x bigger than the other... Screen.width seems to be scaled down, and not in actual pixels. If I select Iphone X the width is like 446 iirc.

    If I switch back to game view (not simulator), the sizes are at least the same and the dimensions seems to be actual pixels, but often the screen orientation is wrong, reporting portrait when the ratio is a landscape (I think it just keeps what's in the simulator even if the simulator is not open).

    I tried in Unity 2020.3.4 with device simulator 3.0.0-preview and that last of the 2.x line.
     
  2. bobbaluba

    bobbaluba

    Joined:
    Feb 27, 2013
    Posts:
    81
    I was accessing Screen.width from within callback in OnInpsectorGUI. It seems it is correct if I call it from within MonoBehaviour.Update(), though.