Any plans to implement a Compass API for the new Input System? Or any alternative?

The old input system can access a phone’s compass using Input.compass, but even though the new InputSystem has been out for several years Unity still hasn’t implemented a compass API. The docs just say “No corresponding API yet.”

This is a massive problem because on Android it’s not possible to use both the old input system and the new one at the same time, if you’re using the new system and attempting to access Input.compass it always returns a heading of 0.

For this project I have to use the new input system, is there any way to access the phone’s compass when using this?

The closest workaround I’ve managed is to try to calculate the compass heading by reading the AttitudeSensor and doing swing twist decomposition along the up vector to get the component of the device’s rotation around the y axis. This doesn’t work well because you get odd influences from the other two axes, the quaternion returned by the attitude sensor itself seems to be inconsistent with the device’s real world orientation. It also seems insane to be juggling quaternions and bodging something together when phones have actual compasses that work accurately.

1 Like

This Guide doesn’t mention MagneticFieldSensor. I believe this is it, but I didn’t test that.

I came across a similar comment you made elsewhere while searching for a solution, but the docs seemed to indicate it’s not remotely the same thing.

The docs for magnetic field sensor simply say it returns the magnetic field strength near the device. The compass returns the heading of the device to true north or magnetic north.

I could sample the sensor and find out what data it’s returning but I wouldn’t bet on it.

1 Like