Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Help with sensors using the InputSystem

Discussion in 'Input System' started by Iphychoo, Jun 16, 2020.

  1. Iphychoo

    Iphychoo

    Joined:
    Sep 26, 2012
    Posts:
    12
    Hi, i'm trying to use the stepcounter sensor on android! but i'm having trouble finding any useful information regarding setting up the sensors for Android. Can someone please guide me in the right direction, I'm trying to count steps and when the app is opened show the amount of steps done.

    Thanks
     
  2. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    When a step counter is present on the device, there should be a `StepCounter.current` device that can be enabled with

    Code (CSharp):
    1. InputSystem.EnableDevice(StepCounter.current);
    The step count can be read out either directly

    Code (CSharp):
    1. StepCounter.current.stepCounter.ReadValue();
    Or by binding to it from actions

    Code (CSharp):
    1. "<StepCounter>/stepCounter"
     
    Roman_Keivan and Iphychoo like this.
  3. Iphychoo

    Iphychoo

    Joined:
    Sep 26, 2012
    Posts:
    12

    Hi Rene-Damm,

    Thanks for the reply, thats exactly how I got it working. :) I was wondering is there any point setting up step counter sensor in the input actions? Or is there no need for it.
     
  4. renelie_s

    renelie_s

    Joined:
    Feb 29, 2020
    Posts:
    7
    Hi Rene-Damm,

    How do we reset the step counter's value to 0?
    I tried
    StepCounter.current.stepCounter.ProcessValue(0)
    but it doesn't work.

    EDIT:
    Also, is there a way to make the StepCounter run in background?
    This
    StepCounter.current.canRunInBackground
    returns false all the time.
     
  5. airevgeny

    airevgeny

    Joined:
    Nov 10, 2019
    Posts:
    2
    Hi, renelie_s, how did you solve these problems?
     
  6. renelie_s

    renelie_s

    Joined:
    Feb 29, 2020
    Posts:
    7
    Hei, @airevgeny I'm so sorry for the delayed response. I never got to implement the InputSystem's StepCounter for iOS on my project because as per this document, iOS StepCounter is still not supported.

    So, as an alternative, in my project I'm using Accelerometer as a StepCounter instead. It's not really counting real, physical steps though as the Accel counts any physical movement with the device, but if with some calibration, Accel can mimic a StepCounter.

    Still would appreciate it when Unity supports StepCounter for iOS in their InputSystem though.
     
    airevgeny likes this.
  7. Roman_Keivan

    Roman_Keivan

    Joined:
    May 31, 2019
    Posts:
    21
    Thanks Rene-Damm, It's helped to me.
     
  8. Balder92

    Balder92

    Joined:
    Jan 25, 2014
    Posts:
    2
    Hi @Rene-Damm
    I am working on a project now where i am trying to use the StepCounter.
    I have confirmed that the stepcounter.current returns AndroidStepCounter:/AndroidStepCounter.
    So I should have it enabled. however the
    Code (CSharp):
    1. StepCounter.current.stepCounter.ReadValue()
    always returns 0. including a screenshot of my Android Logcat, incase the information there is helpful to anyone. I can't seem to get anything useful out of it.
    image_2022-06-09_224525458.png

    Thank you to anyone who is able to help me!
     
  9. DianaRG_Dinorekkos

    DianaRG_Dinorekkos

    Joined:
    Jan 15, 2021
    Posts:
    1
    Hi I have the same problem, I'm trying to make the step counter work but it always return 0.

    I do initialize the devide like this.

    InputSystem.AddDevice<StepCounter>();
    if (StepCounter.current != null)
    {
    Debug.Log("Sensor found!");
    InputSystem.EnableDevice(StepCounter.current);
    StepCounter.current.MakeCurrent();
    }

    But the counter return 0 :C

    if (StepCounter.current != null && StepCounter.current.enabled)
    {
    OnStep(StepCounter.current.stepCounter.ReadValue(), 0);
    Debug.Log("TotalSteps: "+ StepCounter.current.stepCounter.ReadValue());
    }