Search Unity

Weird Screen.safeArea behavior on Android

Discussion in 'Android' started by Alvaro_Platonic, Jun 27, 2019.

  1. Alvaro_Platonic

    Alvaro_Platonic

    Joined:
    Jun 27, 2019
    Posts:
    1
    Hello! :)

    I've observed strange safeArea rect values while trying to update: in some versions, the rect size is correct, but the vertical position ignores the presence of the notch in portrait orientation. Landscape works perfectly.
    I saw here that 2018.4.1 and 2019.1.2 added some important fixes for safeArea, so I tried different versions.
    Test device is Huawei P20, with a 1080*2244 screen and a notch at the top-center.
    Results:

    2018.3.14 is the only one that seems to work nicely.
    Also, I took the values several times to make sure the screen was fully settled down after app initialization.

    Am I doing something wrong, or misunderstanding how it should be working?
    I tried to find out similar cases, but the ones I found didn't show this particular behavior, and I'd like to know better before filing an issue.

    Thank you! ^-^
     
    gelllard likes this.
  2. Achoo

    Achoo

    Joined:
    Jun 4, 2015
    Posts:
    9
    I have the same issue, did you find how to resolve it or is it Unity?
     
  3. rjonaitis

    rjonaitis

    Unity Technologies

    Joined:
    Jan 5, 2017
    Posts:
    115
    The Screen.safeArea values are returned in screen space ( origin(0,0) is at left bottom corner), so you are getting y=0 because that is the offset from bottom of the screen and the notch is at the top of the screen.

    the 2018.3.14 had a bug where it was returning Screen.safeArea values in UI space ( origin(0,0) at left top corner). Quote from your link: "Unity 2018.3.0 added support for notched devices running Android 9.0 and above. Unfortunately, it contained several bugs, one of which rendered the safe area upside down."