Skip to content

Commit 71e8103

Browse files
FIX: GetBindingDisplayString returns empty for composites filtered by group-based binding mask [UUM-141423] (#2414)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 145da6d commit 71e8103

3 files changed

Lines changed: 67 additions & 1 deletion

File tree

Assets/Tests/InputSystem/CoreTests_Actions.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9245,6 +9245,53 @@ public void Actions_WhenGettingDisplayTextForBindingsOnAction_CompositesAreForma
92459245
Assert.That(action.GetBindingDisplayString(8), Is.EqualTo("Left Shift|Right Shift+A"));
92469246
}
92479247

9248+
// https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-141423
9249+
[Test]
9250+
[Category("Actions")]
9251+
public void Actions_WhenGettingDisplayTextForBindingsOnAction_CompositeIsIncludedWhenAtLeastOnePartMatchesBindingMask()
9252+
{
9253+
var action = new InputAction();
9254+
9255+
action.AddCompositeBinding("1DAxis")
9256+
.With("Negative", "<Keyboard>/a", groups: "Keyboard")
9257+
.With("Positive", "<Keyboard>/d", groups: "Keyboard");
9258+
9259+
Assert.That(action.GetBindingDisplayString(InputBinding.MaskByGroup("Keyboard")),
9260+
Is.EqualTo("A/D"));
9261+
}
9262+
9263+
// https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-141423
9264+
[Test]
9265+
[Category("Actions")]
9266+
public void Actions_WhenGettingDisplayTextForBindingsOnAction_MixedGroupCompositeIsRenderedAtomicallyWhenAnyPartMatchesBindingMask()
9267+
{
9268+
var action = new InputAction();
9269+
9270+
action.AddCompositeBinding("1DAxis")
9271+
.With("Negative", "<Keyboard>/a", groups: "Keyboard")
9272+
.With("Positive", "<Mouse>/leftButton", groups: "Mouse");
9273+
9274+
Assert.That(action.GetBindingDisplayString(InputBinding.MaskByGroup("Keyboard")),
9275+
Is.EqualTo("A/LMB"));
9276+
Assert.That(action.GetBindingDisplayString(InputBinding.MaskByGroup("Mouse")),
9277+
Is.EqualTo("A/LMB"));
9278+
}
9279+
9280+
// https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-141423
9281+
[Test]
9282+
[Category("Actions")]
9283+
public void Actions_WhenGettingDisplayTextForCompositeWithNoMatchingGroups_IsExcluded()
9284+
{
9285+
var action = new InputAction();
9286+
9287+
action.AddCompositeBinding("1DAxis")
9288+
.With("Negative", "<Keyboard>/a", groups: "Keyboard")
9289+
.With("Positive", "<Keyboard>/d", groups: "Keyboard");
9290+
9291+
Assert.That(action.GetBindingDisplayString(InputBinding.MaskByGroup("Gamepad")),
9292+
Is.Empty);
9293+
}
9294+
92489295
// https://fogbugz.unity3d.com/f/cases/1321175/
92499296
[Test]
92509297
[Category("Actions")]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Fixed
1111

12+
- Fixed `InputActionRebindingExtensions.GetBindingDisplayString(InputAction, InputBinding, ...)` returning an empty string for composite bindings when the binding mask filters by group [UUM-141423](https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-141423)
1213
- Fixed `InputEventPtr.handled` not preventing actions from triggering when switching devices. The default event handled policy has been changed from `SuppressStateUpdates` (now deprecated) to `SuppressActionEventNotifications`, which keeps device state synchronized while suppressing action callbacks for handled events. [ISXB-1097](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1097)
1314
- Fixed all `InputAction.WasXxxThisFrame()` and `WasXxxThisDynamicUpdate()` polling APIs to use per-action suppression tracking instead of a map-wide flag. Previously, when multiple events arrived in the same frame with mixed handled/unhandled states, the last event's suppression state could incorrectly affect all actions in the map. [ISXB-1097](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1097)
1415
- Fixed `InputRecorder` playback not starting when the Game View is not focused in the Editor [ISXB-1319](https://jira.unity3d.com/browse/ISXB-1319)

Packages/com.unity.inputsystem/InputSystem/Runtime/Actions/InputActionRebindingExtensions.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,25 @@ public static string GetBindingDisplayString(this InputAction action, InputBindi
321321
if (bindings[i].isPartOfComposite)
322322
continue;
323323
if (!bindingMask.Matches(bindings[i]))
324-
continue;
324+
{
325+
// Composites are filtered atomically: any matching part promotes the whole
326+
// composite, consistent with how the index-based GetBindingDisplayString
327+
// overload below treats composites as one display unit; per-part filtering
328+
// would require a separate API.
329+
if (!bindings[i].isComposite)
330+
continue;
331+
var anyPartMatches = false;
332+
for (var partIndex = i + 1; partIndex < bindings.Count && bindings[partIndex].isPartOfComposite; ++partIndex)
333+
{
334+
if (bindingMask.Matches(bindings[partIndex]))
335+
{
336+
anyPartMatches = true;
337+
break;
338+
}
339+
}
340+
if (!anyPartMatches)
341+
continue;
342+
}
325343

326344
////REVIEW: should this filter out bindings that are not resolving to any controls?
327345

0 commit comments

Comments
 (0)