Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[New Input System] EnableDevice error

Discussion in 'Input System' started by opdenis, Apr 23, 2020.

  1. opdenis

    opdenis

    Joined:
    Jan 23, 2017
    Posts:
    15
    I am using this code:
    Code (csharp):
    1.  InputSystem.EnableDevice(StepCounter.current);
    But Android Studio LogCat shows the errors:
    What is the correct way to get the StepCounter working?
    Is there any examples?
     
    Roman_Keivan likes this.
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    If it's null, it means that either there's no step counter present on the device or that it hasn't been created yet.
     
    Roman_Keivan likes this.
  3. opdenis

    opdenis

    Joined:
    Jan 23, 2017
    Posts:
    15
    Step counter IS present - I have other app, that works correctly with that sensor.
    So I have to ask - How should I create the counter? Is there any working sample with Android sensors?
     
    Roman_Keivan likes this.
  4. opdenis

    opdenis

    Joined:
    Jan 23, 2017
    Posts:
    15
    Does anybody have the working example?
     
    Roman_Keivan likes this.
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Are you on Android 10? Seems like accessing the step counter requires requesting ACTIVITY_RECOGNITION permission in the manifest now.

    Could you file a bug with the Unity bug reporter? Our mobile platform guys should have a look at this I think.
     
    Roman_Keivan likes this.
  6. opdenis

    opdenis

    Joined:
    Jan 23, 2017
    Posts:
    15
    Thank you!
    Its Mi5 with LineageOS 15.1 (Android 8.1.0).
    Should I send bug report or try to add ACTIVITY_RECOGNITION permission first?
     
    Roman_Keivan likes this.
  7. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Feel free to just open a ticket.

    Adding ACTIVITY_RECOGNITION on your end may work around the issue for now and unblock you until we have a fix out.
     
    Roman_Keivan likes this.
  8. opdenis

    opdenis

    Joined:
    Jan 23, 2017
    Posts:
    15
    Thank you, but how can I add custom permission without repacking the APK?
     
    Roman_Keivan likes this.
  9. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Haven't tried doing this myself but from what I understand, you can override the builtin manifest by putting one in Assets/Plugins/Android. See docs and this.
     
    Roman_Keivan likes this.
  10. opdenis

    opdenis

    Joined:
    Jan 23, 2017
    Posts:
    15
    Hm. Still can't use it:
    Code (CSharp):
    1.   private void OnEnable()
    2.   {
    3.     InputSystem.EnableDevice(StepCounter.current);
    4.   }
    5.  
    6.   void Start()
    7.   {
    8.     Debug.Log(StepCounter.current.enabled.ToString());
    9.   }
    LogCat shows:
    E/Unity: NullReferenceException: Object reference not set to an instance of an object
    at Pedometer.Start ()

     
    Roman_Keivan likes this.
  11. vandel212

    vandel212

    Joined:
    May 10, 2020
    Posts:
    24
    Has there been any progress made on this? I'm running in to the same issue.
     
    Roman_Keivan likes this.
  12. frpe1

    frpe1

    Joined:
    May 4, 2020
    Posts:
    10
    First I discovery the same error when using acceleratometer as well as step counter. But later I also discovery that it did work on my device!.
    But its not (obviously) working in game mode in Unity editor. that value become null

    So I simple used
    Code (CSharp):
    1. if (Accelerometer.current != null)
    2.      InputSystem.EnableDevice(Accelerometer.current);
    and its important also to make sure the DisableDevice as well using a check or else
    it will generate an error on the computer app.

    Code (CSharp):
    1. if (Accelerometer.current != null)
    2.      InputSystem.DisableDevice(Accelerometer.current);
    To come around that issue. Now its not a problem anymore or other sensors either.
    Using the same simple check.

    If I also putting these sensor check in my Custom Input Manager class
    I setting [DefaultExecutionOrder(-1)] for the class as well, to make sure
    it is initialized before other classes in my app.


    using:
    input system 1.1.0-preview.3
    XR Interaction toolkit 0.10.0-preview 7
    XR Plugin management 3.2.17
    Unity 2020.2.6f1
    and AR foundation and AR core 4.1.1

    Was builded for AR, so now it works just fine!
     
    Last edited: Mar 7, 2021
    Roman_Keivan and apiotuch_unity like this.