Skip to content

Commit 5b7ad60

Browse files
author
Rene Damm
authored
FIX: Calling IsPressed() on device being true (1374024, #1464).
1 parent 0dbf8cd commit 5b7ad60

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Controls.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,35 @@ public void Controls_CanFindControlsUsingWildcards_InMiddleOfNames()
10321032
}
10331033
}
10341034

1035+
[Test]
1036+
[Category("Controls")]
1037+
public void Controls_CanDetermineIfControlIsPressed()
1038+
{
1039+
InputSystem.settings.defaultButtonPressPoint = 0.5f;
1040+
1041+
var gamepad = InputSystem.AddDevice<Gamepad>();
1042+
1043+
Set(gamepad.leftStick, Vector2.one);
1044+
Set(gamepad.leftTrigger, 0.6f);
1045+
Press(gamepad.buttonSouth);
1046+
1047+
//// https://jira.unity3d.com/browse/ISX-926
1048+
////REVIEW: IsPressed() should probably be renamed. As is apparent from the calls here, it's not always
1049+
//// readily apparent that the way it is defined ("actuation level at least at button press threshold")
1050+
//// does not always connect to what it intuitively means for the specific control.
1051+
1052+
Assert.That(gamepad.leftTrigger.IsPressed(), Is.True);
1053+
Assert.That(gamepad.rightTrigger.IsPressed(), Is.False);
1054+
Assert.That(gamepad.buttonSouth.IsPressed(), Is.True);
1055+
Assert.That(gamepad.buttonNorth.IsPressed(), Is.False);
1056+
Assert.That(gamepad.leftStick.IsPressed(), Is.True); // Note how this diverges from the actual meaning of "is the left stick pressed?"
1057+
Assert.That(gamepad.rightStick.IsPressed(), Is.False);
1058+
1059+
// https://fogbugz.unity3d.com/f/cases/1374024/
1060+
// Calling it on the entire device should be false.
1061+
Assert.That(gamepad.IsPressed(), Is.False);
1062+
}
1063+
10351064
[Test]
10361065
[Category("Controls")]
10371066
public void Controls_CanCustomizeDefaultButtonPressPoint()

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ however, it has to be formatted properly to pass verification tests.
2121

2222
- Fixed writing values into the half-axis controls of sticks (such as `Gamepad.leftStick.left`) producing incorrect values on the stick ([case 1336240](https://issuetracker.unity3d.com/issues/inputtestfixture-tests-return-inverted-values-when-pressing-gamepads-left-or-down-joystick-buttons)).
2323
- Fixed setting size of event trace in input debugger always growing back to largest size set before.
24-
- Fixed InputSystemUIInputModule showing incorrect bindings after pressing the 'Fix UI Input Module' button in PlayerInput component([case 1319968](https://issuetracker.unity3d.com/product/unity/issues/guid/1319968/)).
24+
- Fixed `InputSystemUIInputModule` showing incorrect bindings after pressing the 'Fix UI Input Module' button in PlayerInput component([case 1319968](https://issuetracker.unity3d.com/product/unity/issues/guid/1319968/)).
2525
- Fixed an issue where UI button clicks could be ignored by `InputSystemUIInputModule` if modifying on-screen devices from Update() callbacks ([case 1365070](https://issuetracker.unity3d.com/product/unity/issues/guid/1365070)).
2626
- Fixed an issue with `InputSystemUIInputModule` that would cause UI to stop responding during play mode after changing a script file while Recompile and Continue mode is active, or by forcing a script recompile using `RequestScriptCompilation`([case 1324215](https://issuetracker.unity3d.com/product/unity/issues/guid/1324215/)).
2727
- Fixed `InputSystemUIInputModule` inspector showing all action bindings as "None" when assigned a runtime created actions asset ([case 1304943](https://issuetracker.unity3d.com/issues/input-system-ui-input-module-loses-prefab-action-mapping-in-local-co-op)).
2828
- Fixed a problem with UI Toolkit buttons remaining active when multiple fingers are used on a touchscreen, using `InputSystemUIInputModule` with pointerBehavior set to `UIPointerBehavior.SingleUnifiedPointer`. UI Toolkit will now always receive the same pointerId when that option is in use, regardless of the hardware component that produced the pointer event. ([case 1369081](https://issuetracker.unity3d.com/issues/transitions-get-stuck-when-pointer-behavior-is-set-to-single-unified-pointer-and-multiple-touches-are-made)).
2929
- Fixed DualSense on iOS not inheriting from `DualShockGamepad` ([case 1378308](https://issuetracker.unity3d.com/issues/input-dualsense-detection-ios)).
3030
- Fixed a device becoming `.current` (e.g. `Gamepad.current`, etc) when sending a new state event that contains no control changes (case 1377952).
31+
- Fixed calling `IsPressed` on an entire device returning `true` ([case 1374024](https://issuetracker.unity3d.com/issues/inputcontrol-dot-ispressed-always-returns-true-when-using-new-input-system)).
3132

3233
#### Actions
3334

Packages/com.unity.inputsystem/InputSystem/Controls/InputControlExtensions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static TControl FindInParentChain<TControl>(this InputControl control)
4141
return null;
4242
}
4343

44+
////REVIEW: This ist too high up in the class hierarchy; can be applied to any kind of control without it being readily apparent what exactly it means
4445
/// <summary>
4546
/// Check whether the given control is considered pressed according to the button press threshold.
4647
/// </summary>
@@ -99,8 +100,14 @@ public static bool IsActuated(this InputControl control, float threshold = 0)
99100
var magnitude = control.EvaluateMagnitude();
100101
if (magnitude < 0)
101102
{
102-
////REVIEW: we probably want to do a value comparison on this path to compare it to the default value
103-
return true;
103+
// We know the control is not in default state but we also know it doesn't support
104+
// magnitude. So, all we can say is that it is actuated. Not how much it is actuated.
105+
//
106+
// If we're looking for a specific threshold here, consider the control to always
107+
// be under. But if not, consider it actuated "by virtue of not being in default state".
108+
if (Mathf.Approximately(threshold, 0))
109+
return true;
110+
return false;
104111
}
105112

106113
if (Mathf.Approximately(threshold, 0))

0 commit comments

Comments
 (0)