Hello,
If I call Input.ResetAllAxes() it works fine with keyboard and buttons, as expected, but is doing absolutely nothing with axes. This is the code that I am using:
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if(Input.GetKey(KeyCode.Space))
{
Input.ResetInputAxes();
Debug.Log ("Resetting Axes: " + h + ", " + v);
}
I am battling a bug that is present since Unity 5.5 which upon refocusing the application makes axis input maxed out either in -1 or 1, if I am listening to input from all joysticks. I’ve narrowed it down to the bug being related to a joystick device that has no name. I must now try and find out which device is causing that, but while trying to troubleshoot the problem and find the actual cause and way around it I attempted to reset the input on application refocus, only to stumble onto this bug as well.
Can anyone else confirm this behavior?
Uhm, I’m not sure if the code you posted is you actual testing code, however the way you have structured those 7 lines doesn’t make too much sense. You first read the axis and then you reset the axes. Of course the values stored in h and v won’t be affected as a float value is a value type. Calling ResetInputAxes after you read h and v won’t change them. You need to read the values after resetting them:
if(Input.GetKey(KeyCode.Space))
{
Input.ResetInputAxes();
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Debug.Log ("Resetting Axes: " + h + ", " + v);
}
If you need h and v outside that code block you can do either
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if(Input.GetKey(KeyCode.Space))
{
Input.ResetInputAxes();
// re-read the values after reset
h = Input.GetAxis("Horizontal");
v = Input.GetAxis("Vertical");
Debug.Log ("Resetting Axes: " + h + ", " + v);
}
Or simply:
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
if(Input.GetKey(KeyCode.Space))
{
Input.ResetInputAxes();
// force the local copies to "0"
h = 0;
v = 0;
Debug.Log ("Resetting Axes: " + h + ", " + v);
}