Accelerometer.current == null, but Input.acceleration used to work fine

Making a mobile game where the player moves side to side by tilting the device. Input.acceleration used to work to move the character.

Switching over to the new Accelerometer.current.acceleration.ReadDefaultValue() method does not work for me due to Accelerometer.current returning null.

Does anyone have a solution to this? Below is a snippet of the check I’m using to enable the Accelerometer and to get it’s current value.

    private void OnEnable()
    {
        gameplayInputsActions.Enable();
        if (Accelerometer.current != null)
        {
            InputSystem.EnableDevice(Accelerometer.current);
        }
    }

    private void OnDisable()
    {
        gameplayInputsActions.Disable();

        if (Accelerometer.current != null)
        {
            InputSystem.DisableDevice(Accelerometer.current);
        }
    }

private void Update()
    {
        if (Accelerometer.current != null)
        {
            Debug.Log(Accelerometer.current.acceleration.ReadValue());
        }

        ReceiveAxisInput();
       //ReceieveTapInput();
    }

    private void ReceiveAxisInput()
    {
        switch (currentControlScheme)
        {
            case ControlScheme.Tilt:
                Vector3 acceleration = gameplayInputsActions.Player.Movement.ReadValue<Vector2>();

                Vector3 tilt = Accelerometer.current != null ? Accelerometer.current.acceleration.ReadDefaultValue() : Vector3.zero;
              
                Vector3 targetVector = acceleration + tilt;
                //Debug.Log(acceleration);
                axisInput = targetVector;

                break;
            case ControlScheme.Drag:
                break;
        }

        //Vector2 keyInput = moveAction;

        Vector2 targetInput = axisInput;

        axisInput = targetInput;
    }

On which platform, which unity version, which input system version?
If you connect to a player via window → analysis → input debugger → remote does it see any accelerometer sensors?

Platform: Android Samsung Galaxy S20+
Unity Version: 2020.3.16f1
Input System Version: 1.0.2

I assume this what you’re talking about? There doesn’t seem to be an accelerometer under my mobile device.
7549045--933040--upload_2021-10-5_11-19-29.png

7549045--933040--upload_2021-10-5_11-19-29.png

Look into this more today and I’m still not able to figure out why this isn’t working. I’ve tried every sensor of this official unity list and I can’t get it working.

Can anyone link me to a tutorial or give me a breakdown of how to get mobile game tilt controls? Something like Doodle Jump where you rotate the phone side-to-side to get the character to move?

I’ve tried the *.current.ReadDefaultValue() of all of these listed below.

  • LinearAccelerationSensor
  • Gyroscope
  • AttitudeSensor
  • AccelerometerSensor

Did you resolve this.
My Accelerometer was working fine using Input System Version 1.0.2.
Then I updated to 1.1.1 and now Accelerometer.current is always null with no other changes.
I will look into it more tomorrow.

Unfortunately I did not resolve this. I ended up toggling the preferred input system to “both”- in the project settings to use the new system and the old system in tandem so I could continue using input.acceleration

Solved in 1.2.0.
Accelerometer null is mentioned as a fix in the release notes.

It’s been quite some time since I made this thread. Much appreciated for you updating me on this after all this time. Thank you so much, I’ll be checking this out today.