Gravity is an Unsupported Device on iOS?

Hello!

I’m refactoring my game to use the new input system and running into an issue that’s blocking me from reaching parity. We used to use UnityEngine.Input.gyro.gravity for accessing gravity, but found it broke on iOS after switching over to using GravitySensor.

I use the system by calling InputSystem.EnableDevice(GravitySensor.current) in Start (also tried in onDeviceAdded and Update just in case), and accessing GravitySensor.current.gravity.ReadValue() later. This works on Android - and seems like it should work on iOS according to the documentation.

I’ve been trying to debug this for a while now. I’m thinking it’s a Input System bug, but it’s totally possible there’s some setup step I’ve missed.

First I noticed that under supported devices it all seemed to be related to Android:

This lead me to do a bit of digging in the source code and I found there is an AndroidSensors.cs, but no matching iOSSensors.cs. There actually was one at one point, but it was removed?

I began to wonder if it was just not being picked up right because there was no matching supported device. At one point in our project, I had InputSystem.settings supported devices explicitly set to include GravitySensor. I completely emptied that supported device list (as stated to support everything possible) and created a display to show me the list of InputSystem.devices and InputSystem.GetUnsupportedDevices() on device. Now here is what I see on and iPad Pro (9.7-inch):

At this point I think I’ve hit a bit of a wall. I believe my next step would be to try to add gravity as a custom device via these instructions. However I’m a bit wary to spend too much time on implementing that if it is in fact a bug, since testing would require device builds.

So my questions from here are:

  • Does this seem to be a bug, or is there something I’m doing wrong?
  • If it’s a bug, would it be viable to write my own custom device to support it for the time being? If so, any advice here would be great.

I think my only other solution at this point would be to turn on support for both the old and new input system and use the old system’s gyro call.

FWIW: I’m on InputSystem 1.0.0, Unity 2019.3.13, and I’ve searched the forums/issues list and couldn’t find anything related.

Thank you!

1 Like

Hey there!

I can ask around for you and see if this appears to be a bug, hopefully this’ll help!

Turns out this was broken by me some time ago and went undetected as we’re missing tests for this :frowning:

@awallick-sd Could you file a ticket with the bug reporter in Unity? (in the editor’s main menu, it’s under “Help >> Report a Bug…”) Will ensure this will get properly checked and verified by QA. We’ll make sure this gets fixed in the next package. Sorry for the bump.

Just occurred to me, while we haven’t pushed out a fix yet, you should (haven’t actually verified this) be able to work around the problem by doing the following somewhere in the initialization code for your app.

InputSystem.RegisterLayoutMatcher("GravitySensor",
    new InputDeviceMatcher()
        .WithInterface("iOS")
        .WithDeviceClass("Gravity"));
1 Like

@Shaunyowns , @Rene-Damm - thank you for the quick responses! I went ahead and submitted the bug report.

I tried your workaround and am happy to say it works! I’ll keep this code in for the time being and keep an eye on the releases. Thanks again!

1 Like

Fix pending. Should be in next package.

1 Like