FIX: Fixed incorrect default state for axes on some controllers. #870
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a control does not have an explicit defaultState argument to the InputControl attribute, the default state is considered to be 0. But for axis controls which are normalized to return values from -1..1, and which are represented by an unsigned integer on the device, 0 is not the correct default value for the input state. This meant that the axis would be considered to be at it's default value when at -1. This is common for gamepad access, and would result in canceled callbacks being sent when moving the axis towards -1.
Now, in combination with my previous fix here: https://github.com/Unity-Technologies/InputSystem/pull/828/files#diff-a82dc3439d6b317a87e69ff2cdc0bc0a , which would always return 0 values for canceled interactions, this would mean that moving a gamepad stick all the way to the left would generate a value of 0, which completely broke the Input System.
This PR automatically generates default values for axes when no default is explicitly set and when normalizeZero is used, which fixes the problem. This is the best fix I could think of - I also considered adding default values everywhere (but that would have been much work, and easy to get wrong or miss a place), or to ignore any controls without explicit default values for
CheckStateIsAtDefault, but that would skip optimizations and possibly change behavior).