Skip to content

Commit 8b13d7d

Browse files
FIX: Gamepad stick inputs are not recognized in WebGL Player (ISXB-1090) (#2165)
1 parent 9a1142c commit 8b13d7d

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

Assets/Tests/InputSystem/Plugins/UITests.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,26 +2871,29 @@ public IEnumerator UI_CanOperateMultiplayerUILocallyUsingGamepads()
28712871

28722872
[UnityTest]
28732873
[Category("UI")]
2874-
public IEnumerator UI_CanDriveUIFromGamepad()
2874+
2875+
[TestCase("Gamepad", ExpectedResult = 1)]
2876+
#if UNITY_WEBGL || UNITY_EDITOR
2877+
[TestCase("WebGLGamepad", ExpectedResult = 1)]
2878+
#endif
2879+
public IEnumerator UI_CanDriveUIFromGamepad(string deviceLayout)
28752880
{
2876-
var gamepad = InputSystem.AddDevice<Gamepad>();
2881+
var gamepad = (Gamepad)InputSystem.AddDevice(deviceLayout);
28772882

28782883
var scene = CreateTestUI();
28792884

2880-
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
2881-
var map = asset.AddActionMap("map");
2882-
var moveAction = map.AddAction("move", type: InputActionType.PassThrough, binding: "<Gamepad>/*stick");
2883-
var submitAction = map.AddAction("submit", type: InputActionType.PassThrough, binding: "<Gamepad>/buttonSouth");
2884-
var cancelAction = map.AddAction("cancel", type: InputActionType.PassThrough, binding: "<Gamepad>/buttonEast");
2885+
var actions = new DefaultInputActions();
28852886

2886-
scene.uiModule.move = InputActionReference.Create(moveAction);
2887-
scene.uiModule.submit = InputActionReference.Create(submitAction);
2888-
scene.uiModule.cancel = InputActionReference.Create(cancelAction);
2887+
scene.uiModule.move = InputActionReference.Create(actions.UI.Navigate);
2888+
scene.uiModule.submit = InputActionReference.Create(actions.UI.Submit);
2889+
scene.uiModule.cancel = InputActionReference.Create(actions.UI.Cancel);
28892890

28902891
scene.uiModule.moveRepeatDelay = 0.1f;
28912892
scene.uiModule.moveRepeatRate = 0.1f;
28922893

2893-
map.Enable();
2894+
actions.Enable();
2895+
Assert.That(actions.UI.enabled, Is.True);
2896+
Assert.That(actions.Player.enabled, Is.True);
28942897

28952898
yield return null;
28962899

@@ -2913,7 +2916,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
29132916
OneEvent("type", EventType.Move),
29142917
OneEvent("device", gamepad),
29152918
OneEvent("moveDir", MoveDirection.Right),
2916-
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
2919+
OneEvent("moveVector", new Vector2(1.0f, 0.0f))));
29172920
Assert.That(scene.rightChildReceiver.events, Is.Empty);
29182921

29192922
#if UNITY_INPUT_SYSTEM_INPUT_MODULE_NAVIGATION_DEVICE_TYPE
@@ -2932,7 +2935,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
29322935
OneEvent("type", EventType.Move),
29332936
OneEvent("device", gamepad),
29342937
OneEvent("moveDir", MoveDirection.Left),
2935-
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
2938+
OneEvent("moveVector", new Vector2(-1.0f, 0.0f))));
29362939
Assert.That(scene.rightChildReceiver.events, Is.Empty);
29372940

29382941
scene.leftChildReceiver.events.Clear();
@@ -2946,7 +2949,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
29462949
OneEvent("type", EventType.Move),
29472950
OneEvent("device", gamepad),
29482951
OneEvent("moveDir", MoveDirection.Up),
2949-
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
2952+
OneEvent("moveVector", new Vector2(0.0f, 1.0f))));
29502953
Assert.That(scene.rightChildReceiver.events, Is.Empty);
29512954

29522955
scene.leftChildReceiver.events.Clear();
@@ -2960,7 +2963,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
29602963
OneEvent("type", EventType.Move),
29612964
OneEvent("device", gamepad),
29622965
OneEvent("moveDir", MoveDirection.Down),
2963-
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
2966+
OneEvent("moveVector", new Vector2(0.0f, -1.0f))));
29642967
Assert.That(scene.rightChildReceiver.events, Is.Empty);
29652968

29662969
scene.leftChildReceiver.events.Clear();
@@ -2975,7 +2978,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
29752978
OneEvent("type", EventType.Move),
29762979
OneEvent("device", gamepad),
29772980
OneEvent("moveDir", MoveDirection.Down),
2978-
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
2981+
OneEvent("moveVector", new Vector2(0.0f, -1.0f))));
29792982

29802983
scene.leftChildReceiver.events.Clear();
29812984

@@ -2989,7 +2992,7 @@ public IEnumerator UI_CanDriveUIFromGamepad()
29892992
OneEvent("type", EventType.Move),
29902993
OneEvent("device", gamepad),
29912994
OneEvent("moveDir", MoveDirection.Down),
2992-
OneEvent("moveVector", gamepad.leftStick.ReadValue())));
2995+
OneEvent("moveVector", new Vector2(0.0f, -1.0f))));
29932996

29942997
scene.leftChildReceiver.events.Clear();
29952998

@@ -3031,6 +3034,10 @@ public IEnumerator UI_CanDriveUIFromGamepad()
30313034

30323035
Assert.That(scene.leftChildReceiver.events, Is.Empty);
30333036
Assert.That(scene.rightChildReceiver.events, Is.Empty);
3037+
3038+
actions.Disable();
3039+
Assert.That(actions.UI.enabled, Is.False);
3040+
Assert.That(actions.Player.enabled, Is.False);
30343041
}
30353042

30363043
[Test]

Assets/Tests/InputSystem/Plugins/WebGLTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@ public void Devices_SupportsWebGLStandardGamepads()
4343
Assert.That(gamepad.leftTrigger.ReadUnprocessedValue(), Is.EqualTo(0.123).Within(0.0001));
4444
Assert.That(gamepad.rightTrigger.ReadUnprocessedValue(), Is.EqualTo(0.234).Within(0.0001));
4545

46-
AssertStickValues(gamepad.leftStick, new Vector2(0.345f, -0.456f), -0.456f, 0, 0, 0.345f);
47-
AssertStickValues(gamepad.rightStick, new Vector2(0.567f, -0.678f), -0.678f, 0, 0, 0.567f);
48-
46+
AssertStickValues(gamepad.leftStick, new Vector2(0.345f, -0.456f), 0, 0.456f, 0, 0.345f);
47+
AssertStickValues(gamepad.rightStick, new Vector2(0.567f, -0.678f), 0, 0.678f, 0, 0.567f);
4948

5049
InputSystem.QueueStateEvent(gamepad, new WebGLGamepadState
5150
{
@@ -54,9 +53,8 @@ public void Devices_SupportsWebGLStandardGamepads()
5453
});
5554
InputSystem.Update();
5655

57-
AssertStickValues(gamepad.leftStick, new Vector2(-0.345f, 0.456f), 0, -0.456f, 0.345f, 0);
58-
AssertStickValues(gamepad.rightStick, new Vector2(-0.567f, 0.678f), 0, -0.678f, 0.567f, 0);
59-
56+
AssertStickValues(gamepad.leftStick, new Vector2(-0.345f, 0.456f), 0.456f, 0, 0.345f, 0);
57+
AssertStickValues(gamepad.rightStick, new Vector2(-0.567f, 0.678f), 0.678f, 0, 0.567f, 0);
6058

6159
// Test all buttons.
6260
AssertButtonPress(gamepad, new WebGLGamepadState().WithButton(GamepadButton.South), gamepad[GamepadButton.South]);

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ however, it has to be formatted properly to pass verification tests.
2121
- Fixed an issue when providing JoinPlayer with a specific split screen index. [ISXB-897](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-897)
2222
- Fixed Inspector Window being refreshed all the time when a PlayerInput component is present with Invoke Unity Events nofication mode chosen [ISXB-1448](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1448)
2323
- Fixed an issue where an action with a name containing a slash "/" could not be found via `InputActionAsset.FindAction(string,bool)`. [ISXB-1306](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1306).
24+
- Fixed Gamepad stick up/down inputs that were not recognized in WebGL. [ISXB-1090](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1090)
2425

2526
## [1.14.0] - 2025-03-20
2627

Packages/com.unity.inputsystem/InputSystem/Plugins/WebGL/WebGLGamepad.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ internal unsafe struct WebGLGamepadState : IInputStateTypeInfo
1919
[InputControl(name = "leftStick", offset = 0)]
2020
[InputControl(name = "rightStick", offset = 8)]
2121
[InputControl(name = "leftStick/y", parameters = "invert")]
22-
[InputControl(name = "leftStick/up", parameters = "clamp=2,clampMin=0,clampMax=1,invert")]
23-
[InputControl(name = "leftStick/down", parameters = "clamp=2,clampMin=-1,clampMax=0,invert=false")]
22+
[InputControl(name = "leftStick/up", parameters = "clamp=2,clampMin=-1,clampMax=0,invert")]
23+
[InputControl(name = "leftStick/down", parameters = "clamp=2,clampMin=0,clampMax=1,invert=false")]
2424
[InputControl(name = "rightStick/y", parameters = "invert")]
25-
[InputControl(name = "rightStick/up", parameters = "clamp=2,clampMin=0,clampMax=1,invert")]
26-
[InputControl(name = "rightStick/down", parameters = "clamp=2,clampMin=-1,clampMax=0,invert=false")]
25+
[InputControl(name = "rightStick/up", parameters = "clamp=2,clampMin=-1,clampMax=0,invert")]
26+
[InputControl(name = "rightStick/down", parameters = "clamp=2,clampMin=0,clampMax=1,invert=false")]
2727
// All the buttons we need to bump from single bits to full floats and reset bit offsets.
2828
[InputControl(name = "buttonSouth", offset = ButtonOffset + 0 * 4, bit = 0, format = "FLT")]
2929
[InputControl(name = "buttonEast", offset = ButtonOffset + 1 * 4, bit = 0, format = "FLT")]

0 commit comments

Comments
 (0)