Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Feedback Safe area APIs return wildly incorrect results

Discussion in 'Multiplatform Dev Blitz Day 2023 - Q&A' started by rumorgames, Jun 22, 2023.

  1. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    51
    So I just switched from an iPhone X to iPhone 13 mini and was shocked to find my game's UI was wildly distorted on the new device. After some debugging, I discovered that BOTH safe area APIs (Screen.safeArea and Screen.cutouts) were returning incorrect results. I created a simple app to illustrate the issues:

    image2.png

    Safe area works as expected in portrait mode, but in either landscape orientation it behaves as if it is still in a vertical orientation. In landscape, safe area should be indented on the left, right, and bottom, but flush on the top. Instead it's indented and the bottom and the top, but not the left or right.

    image0.png

    Cutouts are also incorrect, though less reliably so. Rotating through different orientations, cutouts will often report that the notch is on the opposite side of the screen that it actually is. In the above screenshot, the notch is on the left of the screen, but is reported on the right.

    When investigating the cutout issue, I discovered the device simulator in editor does not return cutouts at all for the closest comparable device (iPhone 12 mini). This was confirmed as a bug and forwarded to developers.

    It's pretty disappointing that even when working on a well-supported tech stream (2021.3.27f1) and a two-year old phone (admittedly a lesser-selling model, but still, a recent iPhone, not something nobody's ever heard of), major issues like this go undiagnosed and unaddressed. It feels like every step of trying to get to the bottom of these issues, I stumble onto another landmine. This is all pretty basic stuff that should "just work."
     
  2. its_neil

    its_neil

    Unity Technologies

    Joined:
    Nov 6, 2019
    Posts:
    7
    Hi there, sorry you're having this issue! This would be great if you could submit a bug report to us, attaching your simple app as a Unity project so we can take a look at this.
     
  3. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    51
    I did a few days ago, IN-44671 (Safe Area reporting incorrect results on iPhone 13 mini) and IN-44672 (Cutouts reporting incorrect results on iPhone 13 mini). IN-43268 (Screen.cutouts returns an empty array on certain notched devices in Device Simulator) was confirmed and is now UUM-40513.
     
  4. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    503
    Also having this issue with an iPhone 11. Screen.safeArea reports correctly if the app starts in landscape first. But if it starts in portrait, then the landscape will report a wrong safearea. Tested with 2022.3.4f1. Quite frustrating…
     
  5. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    51
    Good catch, and it looks like the inverse is true as well. Starting in landscape, portrait will end up indented left, right, and bottom instead of top and bottom.

    I'm kind of bewildered how something this obvious and essential can slip through multiple editor releases. @its_neil Even putting aside the bug reports, is there no regression testing to catch stuff like this? The latest release (2021.3.28f1) fixed the cutout issue (thankfully), but safe area is still broken.
     
  6. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    503
    Yeah it also blows my mind. I'm also surprised there's not more people reporting this.

    Anyway my tested workaround for 2022.3.4f1 is to set the games default orientation to LandscapeLeft and then in a Start() method I'll set it to Screen.orientation = ScreenOrientation.AutoRotation;

    Now only the Splash Screen is always LandscapeLeft but afterwards the safearea works. I'm not using cutouts, so not sure about those.
     
  7. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    503
    I hope Apple with approve it :confused:
     
  8. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    51
  9. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    503
    rumorgames likes this.
  10. TCROC

    TCROC

    Joined:
    Aug 15, 2015
    Posts:
    230
    rumorgames likes this.
  11. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    503
  12. marvpaul

    marvpaul

    Joined:
    May 9, 2016
    Posts:
    33
    It's terrible! Just coming from 2022.2.9f1 and updated to 2022.3.10f1 because of Mac OS build problems. Now my project builds for Mac but I can't use it anymore on iOS / Android because of this SafeArea bug. Hope this will be solved very soon. Meanwhile trying your workaround @iddqd
     
  13. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    51
    I can confirm this is finally fixed in 2021.3.31f1.
     
    azevedco, marvpaul and iddqd like this.
  14. Frantasad

    Frantasad

    Joined:
    Oct 25, 2018
    Posts:
    7
    I am getting this again in 2022.3.25
    Why does this keep regressing?
     
  15. rumorgames

    rumorgames

    Joined:
    Nov 28, 2012
    Posts:
    51
    iddqd likes this.