Help with sensors using the InputSystem

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

When a step counter is present on the device, there should be a StepCounter.current device that can be enabled with

InputSystem.EnableDevice(StepCounter.current);

The step count can be read out either directly

StepCounter.current.stepCounter.ReadValue();

Or by binding to it from actions

"<StepCounter>/stepCounter"
2 Likes

Hi Rene-Damm,

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

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.

Hi, renelie_s, how did you solve these problems?

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.

1 Like

Thanks Rene-Damm, It’s helped to me.

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 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.

Thank you to anyone who is able to help me!

2 Likes

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();
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());
}