Safe area APIs return wildly incorrect results

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:

9096973--1260613--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.

9096973--1260610--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.”

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.

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.

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…

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.

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.

I hope Apple with approve it :face_with_spiral_eyes:

@iddqd The bug is “under consideration” for a future fix. Please vote on it for extra visibility:

@rumorgames done

1 Like

@rumorgames @iddqd I also face this issue. I will upvote it. In the mean time, it looks like you may be able to manually access safe area here:

1 Like

The bug is now “In Progress” - nice: Unity Issue Tracker - [iOS] Screen.safeArea is incorrectly updated when rotating the device

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

I can confirm this is finally fixed in 2021.3.31f1.

3 Likes

I am getting this again in 2022.3.25
Why does this keep regressing?

Because Unity’s QA process is broken !

2 Likes