Skip to content

NEW: Input consumption - Priorities instead of complexity [ISX-2510]#2402

Open
Darren-Kelly-Unity wants to merge 46 commits into
developfrom
proof-of-concept/input-consumption
Open

NEW: Input consumption - Priorities instead of complexity [ISX-2510]#2402
Darren-Kelly-Unity wants to merge 46 commits into
developfrom
proof-of-concept/input-consumption

Conversation

@Darren-Kelly-Unity
Copy link
Copy Markdown
Collaborator

@Darren-Kelly-Unity Darren-Kelly-Unity commented Mar 31, 2026

Purpose of this PR

This work advances epic ISX-2510 [6.6] Reliable Interactions: shortcut overlap resolution no longer depends only on automatic composite complexity, which was hard to reason about and produced corner cases. The branch adds an opt-in action priority path (InputSettings.shortcutKeysUseActionPriority plus InputAction.Priority), wires it through InputActionState grouping and InputManagerStateMonitors ordering and consumption, and keeps complexity-based behavior when that setting is off. Design context for the epic is linked from the Jira description.

Release Notes

  • NEW: Opt-in action priority for shortcut overlap resolution — InputSettings.shortcutKeysUseActionPriority and per-action InputAction.Priority. When enabled, higher-priority actions are ordered and can consume overlapping input before lower-priority actions in the same group; the Input Actions editor shows Priority only in this mode. (ISX-2510)
  • CHANGE: InputSettings.shortcutKeysConsumeInput is documented as complexity-based shortcut resolution when action priority is disabled (prior develop behavior). Modifier composites use ordered evaluation when that complexity path is active.

Functional Testing status

Automated coverage added and extended in CoreTests_ActionsPriority.cs and updates in CoreTests_Actions.cs (hold paths, repeated binding presses, priority vs complexity, DefaultInputActions, and related scenarios). Manual passes recommended for Project Settings toggles (shortcutKeysUseActionPriority / shortcutKeysConsumeInput), Input Actions editor visibility of Priority, and play-mode shortcuts that previously relied on complexity-only ordering.

Performance Testing Status

Potential extra work when monitor lists are re-sorted (needToUpdateOrderingOfMonitors) and when action priority changes trigger regrouping updates in InputActionState. No dedicated performance benchmarks were run for this draft; recommend a quick profile on a scene with many simultaneous action monitors if risk tolerance is low.

Overall Product Risks

Technical Risk: 2 — Touches core action state, control grouping memory, and state-change monitor ordering and handled propagation; behavior is gated behind new settings but logic is subtle.

Halo Effect: 2 — Affects any project using shortcut consumption or overlapping bindings across maps; editor UX and serialized assets gain priority fields that persist even when the setting is off.

Class diagram

Git range analyzed: origin/develop...HEAD (merge-base to proof-of-concept/input-consumption tip). Diagram emphasizes priority-based shortcut resolution: settings, action priority, packed monitor indices, action state grouping, and monitor dispatch.

Expand class diagram (Mermaid)
classDiagram
  direction TB

  class InputSettings {
    +shortcutKeysConsumeInput bool
    +shortcutKeysUseActionPriority bool
    IsShortcutResolutionUsingActionPriority bool
    IsShortcutResolutionUsingComplexity bool
  }

  class InputAction {
    +Priority int
  }

  class InputActionMap {
    m_State InputActionState
  }

  class InputActionState {
    ControlGroupingTable
    OnActionPriorityChanged()
    GetComplexityFromMonitorIndex() int
  }

  class InputActionState_ControlGroupingTable {
    Stride int
    GroupElementIndex() int
    PriorityElementIndex() int
  }

  class InputActionStateMonitorIndex {
    <<struct>>
    +Packed long
    Create(map ctrl bind prio) InputActionStateMonitorIndex
    +Priority int
  }

  class IInputStateChangeMonitor {
    <<interface>>
    NotifyControlStateChanged()
  }

  class InputManagerStateMonitors {
    SortMonitorsForDeviceIfNeeded(device)
    FireStateChangeNotifications(device time event)
  }

  class StateChangeMonitorsForDevice {
    SortMonitorsByIndex()
  }

  class InputManager {
    m_StateMonitors InputManagerStateMonitors
  }

  InputAction --> InputActionMap : lives in
  InputActionMap --> InputActionState : owns
  InputAction ..> InputActionState : Priority notifies
  InputActionState ..|> IInputStateChangeMonitor
  InputActionState --> InputSettings : reads resolution mode
  InputActionState +-- InputActionState_ControlGroupingTable : uses table layout
  InputManager --> InputManagerStateMonitors : owns
  InputManagerStateMonitors --> StateChangeMonitorsForDevice : per device
  StateChangeMonitorsForDevice ..> InputActionStateMonitorIndex : unpack monitorIndex
  InputManagerStateMonitors ..> InputActionState : invokes monitors
Loading

Documentation Impact

Changes analyzed: origin/develop...HEAD

User-facing surface: public InputAction.Priority, public InputSettings.shortcutKeysUseActionPriority, and clarified semantics for shortcutKeysConsumeInput.

Already updated on this branch: Documentation~/Settings.md (settings table and shortcut behavior), Documentation~/ActionBindings.md (shortcut section and cross-links), and CHANGELOG.md under Added / Changed.

Residual: After review, confirm cross-references and wording match final API names in generated docs; add release-note polish if UX strings change.

Want draft doc edits beyond what is already in this branch? Reply if you want a pass on TOC, xref targets, or extra examples.

Copy link
Copy Markdown
Contributor

@u-pr u-pr Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May require changes
The review identified several issues ranging from potential runtime exceptions and logic regressions to documentation mismatches. Most notably, there's a priority clamping issue that causes value wrap-around and a potential logic regression in how composite bindings are handled compared to previous versions.

🤖 Helpful? 👍/👎

Comment thread Assets/Samples/ProjectWideActions/ProjectWideActionsExample.cs Outdated
Comment thread Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs Outdated
// can then reset state monitors in the same group.
// NOTE: We don't consume for controls at binding complexity 1. Those we fire in unison.
if (controlGroupingAndComplexity[trigger.controlIndex * 2 + 1] > 1 &&
if (controlGroupingAndPriority[trigger.controlIndex * 2 + 1] > 0 &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high
There is a contradiction between this code and the documentation. The documentation in InputAction.cs (line 207) and the tooltip in InputActionsEditorConstants.cs (line 40) state that "Values 0–1 follow one path; values greater than 1 follow another". However, this check uses > 0, meaning priority 1 will be treated as high priority and mark the event as handled.

Furthermore, this change appears to be a regression for composite bindings. Previously, composites had a "complexity" > 1 and would mark events as handled by default (suppressing simple bindings on the same key). Now, they default to priority 0 and will no longer suppress other actions unless the user manually sets a higher priority. If the intention was to maintain existing behavior while introducing explicit priorities, composites should likely default to a priority > 0 (or the check should remain > 1 with a higher default).

🤖 Helpful? 👍/👎

@@ -2478,7 +2469,7 @@ private void ChangePhaseOfActionInternal(int actionIndex, TriggerState* actionSt
// When we perform an action, we mark the event handled such that FireStateChangeNotifications()
// can then reset state monitors in the same group.
// NOTE: We don't consume for controls at binding complexity 1. Those we fire in unison.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low
This comment still references 'binding complexity 1'. Since the implementation has shifted from complexity-based grouping to priority-based grouping, this comment should be updated to reflect the new criteria (e.g., 'priority 0') to stay consistent with the code.

🤖 Helpful? 👍/👎

Comment thread Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs Outdated
@codecov-github-com
Copy link
Copy Markdown

codecov-github-com Bot commented Mar 31, 2026

Codecov Report

Attention: Patch coverage is 88.52041% with 90 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ets/Tests/InputSystem/CoreTests_ActionsPriority.cs 92.01% 25 Missing ⚠️
...em/InputSystem/Runtime/Actions/InputActionState.cs 79.50% 25 Missing ⚠️
...putSystem/Editor/Settings/InputSettingsProvider.cs 0.00% 16 Missing ⚠️
...System/Editor/UITKAssetEditor/Commands/Commands.cs 0.00% 10 Missing ⚠️
...m/InputSystem/Runtime/InputManagerStateMonitors.cs 95.85% 7 Missing ⚠️
...itor/UITKAssetEditor/Views/ActionPropertiesView.cs 66.66% 4 Missing ⚠️
...stem/InputSystem/Runtime/Actions/InputActionMap.cs 60.00% 2 Missing ⚠️
...em/Editor/UITKAssetEditor/SerializedInputAction.cs 66.66% 1 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2402      +/-   ##
===========================================
+ Coverage    78.13%   78.51%   +0.38%     
===========================================
  Files          483      759     +276     
  Lines        98770   129594   +30824     
===========================================
+ Hits         77169   101745   +24576     
- Misses       21601    27849    +6248     
Flag Coverage Δ
inputsystem_MacOS_2021.3 ?
inputsystem_MacOS_2021.3_project ?
inputsystem_MacOS_6000.0 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.0_project 77.34% <88.50%> (+0.03%) ⬆️
inputsystem_MacOS_6000.2 ?
inputsystem_MacOS_6000.2_project ?
inputsystem_MacOS_6000.3 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.3_project 77.33% <88.50%> (+0.06%) ⬆️
inputsystem_MacOS_6000.4 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.4_project 77.35% <88.50%> (+0.06%) ⬆️
inputsystem_MacOS_6000.5 5.31% <5.82%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.5_project 77.38% <88.50%> (+0.06%) ⬆️
inputsystem_MacOS_6000.6 5.31% <5.82%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.6_project 77.38% <88.50%> (+0.06%) ⬆️
inputsystem_Ubuntu_2021.3 ?
inputsystem_Ubuntu_2021.3_project ?
inputsystem_Ubuntu_2022.3 ?
inputsystem_Ubuntu_6000.0 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.0_project 77.25% <88.50%> (+0.04%) ⬆️
inputsystem_Ubuntu_6000.2 ?
inputsystem_Ubuntu_6000.2_project ?
inputsystem_Ubuntu_6000.3 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.3_project 77.24% <88.50%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.4 5.33% <5.82%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.4_project 77.25% <88.50%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.5 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.5_project 77.28% <88.50%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.6 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.6_project 77.29% <88.50%> (+0.06%) ⬆️
inputsystem_Windows_2021.3 ?
inputsystem_Windows_2021.3_project ?
inputsystem_Windows_6000.0 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_Windows_6000.0_project 77.46% <88.50%> (+0.03%) ⬆️
inputsystem_Windows_6000.2 ?
inputsystem_Windows_6000.2_project ?
inputsystem_Windows_6000.3 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_Windows_6000.3_project 77.46% <88.50%> (+0.06%) ⬆️
inputsystem_Windows_6000.4 5.32% <5.82%> (+<0.01%) ⬆️
inputsystem_Windows_6000.4_project 77.46% <88.50%> (+0.06%) ⬆️
inputsystem_Windows_6000.5 5.31% <5.82%> (+<0.01%) ⬆️
inputsystem_Windows_6000.5_project 77.50% <88.50%> (+0.05%) ⬆️
inputsystem_Windows_6000.6 5.31% <5.82%> (+<0.01%) ⬆️
inputsystem_Windows_6000.6_project 77.51% <88.50%> (+0.05%) ⬆️
linux_2021.3_pkg ?
linux_2021.3_project ?
linux_2022.3_pkg ?
linux_2022.3_project ?
linux_6000.0_pkg ?
linux_6000.0_project ?
linux_6000.1_pkg ?
linux_6000.1_project ?
linux_6000.2_pkg ?
linux_6000.2_project ?
linux_trunk_pkg ?
linux_trunk_project ?
mac_2021.3_pkg ?
mac_2021.3_project ?
mac_2022.3_pkg ?
mac_2022.3_project ?
mac_6000.0_pkg ?
mac_6000.0_project ?
mac_6000.1_pkg ?
mac_6000.1_project ?
mac_6000.2_pkg ?
mac_6000.2_project ?
mac_trunk_pkg ?
mac_trunk_project ?
win_2021.3_pkg ?
win_2021.3_project ?
win_2022.3_pkg ?
win_2022.3_project ?
win_6000.0_pkg ?
win_6000.0_project ?
win_6000.1_pkg ?
win_6000.1_project ?
win_6000.2_pkg ?
win_6000.2_project ?
win_trunk_pkg ?
win_trunk_project ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Samples/InGameHints/InGameHintsActions.cs 15.04% <ø> (-2.66%) ⬇️
Assets/Tests/InputSystem/CoreTests_Actions.cs 98.06% <100.00%> (-0.35%) ⬇️
Assets/Tests/InputSystem/CoreTests_Analytics.cs 99.27% <100.00%> (-0.10%) ⬇️
Assets/Tests/InputSystem/CoreTests_Editor.cs 97.70% <100.00%> (-0.26%) ⬇️
...sts/InputSystem/InputActionCodeGeneratorActions.cs 55.69% <ø> (-3.80%) ⬇️
...nputSystem/Actions/InputActionStateMonitorIndex.cs 100.00% <100.00%> (ø)
...InputSystem/Editor/Analytics/InputBuildAnalytic.cs 78.02% <100.00%> (-1.59%) ⬇️
...tor/UITKAssetEditor/InputActionsEditorConstants.cs 100.00% <ø> (ø)
...untime/Actions/Composites/ButtonWithOneModifier.cs 100.00% <100.00%> (ø)
...ntime/Actions/Composites/ButtonWithTwoModifiers.cs 100.00% <100.00%> (ø)
... and 15 more

... and 279 files with indirect coverage changes

ℹ️ Need help interpreting these results?

Copy link
Copy Markdown
Collaborator

@ekcoh ekcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting up this draft PR. I looked through the tests only so far and I think we should have a discussion around it which would be more helpful than doing asynchronous feedback on the comments. Test cases generally make sense but I fail to decipher some differences and rules in them I fail to understand. Also I am missing tests using priorities when interaction is not a shortcut modifier, I would assume the same rules apply regardless of binding? I think there is opportunity to reduce code diff here by doing some code reuse in the tests without having tests full of if statements.

I also think it would be good to have tests with repeated input which I mentioned before. I didn't spot any such tests unless I missed something. This would look like e.g. with a binding 'X', here value of X button provided as binary

X:                 0 1 1
Action 1 (Prio 1): 0 - 0
Action 2 (Prio 2): 0 1 0
                   a b c

   a: button up, nothing happens
   b: button down, triggers both, but only action 2 fires notification since higher prio
   c: button down again (repeat), triggers none since action 1 saw and reacted to state transition but did not fire

}

[Test]
[Category("Actions Priority")]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If "Actions Priority" is its own category (it makes sense so I like it), could we also move out those tests into e.g. "CoreTests_Actions_Priority.cs" (since partial), to simplify finding these and working with these. This file is way too large.

[Category("Actions Priority")]
[TestCase("ctrl", "x", true)]
[TestCase("ctrl", "x", false)]
public void Actions_Priority_PressingModifierShortcutWithSameBinding_TriggersHighestPriorityAction(string sharedModifier, string binding1, bool legacyComposites)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We some inline doc be added here to explain the arguments? It's not clear to me what binding1 or legacyComposites mean unless I read the whole test. And reading it I am still confused what legacyComposites mean/imply?


map.Enable();

Assert.That(action1.WasPerformedThisFrame(), Is.False);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these asserts, what do they test? Seems like a sanity check or another test? "Actions should not trigger if there is no input"

.With("Modifier", "<Keyboard>/" + sharedModifier)
.With(legacyComposites ? "Button" : "Binding", "<Keyboard>/" + binding1);

action1.Priority = 9;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also valid for
action1.Priority = -2
action2.Priority = -1
?

Comment thread Assets/Tests/InputSystem/CoreTests_Actions.cs Outdated
[Category("Actions Priority")]
[TestCase("ctrl", "shift", "x", false)]
[TestCase("ctrl", "shift", "x", true)]
public void Actions_Priority_BothPrioritiesZero_ConflictingShortcuts_BothPerform(string sharedModifier, string sharedModifier2, string binding1, bool legacyComposites)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also true if both priorities are e.g. 3 right?

Comment thread Assets/Tests/InputSystem/CoreTests_Actions.cs Outdated
Comment thread Assets/Tests/InputSystem/CoreTests_Actions.cs Outdated
Comment thread Assets/Tests/InputSystem/CoreTests_Actions.cs Outdated
Comment thread Assets/Tests/InputSystem/CoreTests_Actions.cs Outdated
@Darren-Kelly-Unity Darren-Kelly-Unity changed the title [Draft ]Proof of concept, input consumption CHANGE: Input consumption - Priorities instead of complexity [ISX-2510] Apr 10, 2026
@Darren-Kelly-Unity Darren-Kelly-Unity changed the title CHANGE: Input consumption - Priorities instead of complexity [ISX-2510] NEW: Input consumption - Priorities instead of complexity [ISX-2510] Apr 10, 2026
Comment thread Assets/Samples/ProjectWideActions/ProjectWideActionsExample.cs Outdated
@ekcoh
Copy link
Copy Markdown
Collaborator

ekcoh commented Apr 29, 2026

@Darren-Kelly-Unity @K-Tone Is this ready for review? It looks to have multiple u-pr comments on it and failing tests indicating it might not be but at the same time it is not a Draft nor having the "work-in-progress" label? I would suggest to either convert back to Draft or add that label for clarity and follow up on outstanding comments to make it clear what the current state is. Feel free to re-request review when ready.

Current things to address:

  • Fix failing tests
  • Fix formatting
  • Follow up on outstanding review comments from previously
  • Run AI review on new state of code

@K-Tone K-Tone added the work in progress Indicates that the PR is work in progress and any review efforts can be post-poned. label Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

work in progress Indicates that the PR is work in progress and any review efforts can be post-poned.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants