Skip to content

FIX: [Port] [UUM-155740] [Input System] Fixed UI Toolkit receiving an extra PointerDownEvent for touch drags - #2502

Open
benoitalain wants to merge 1 commit into
developfrom
fix/uum-159876-touch-double-pointerdown
Open

benoitalain wants to merge 1 commit into
developfrom
fix/uum-159876-touch-double-pointerdown

Conversation

@benoitalain

Copy link
Copy Markdown
Collaborator

Description

Port of the Editor fix for UUM-155740. On iOS and Android, a single-finger drag on a UI Toolkit runtime UI dispatched PointerDownEvent twice: Down, Move, Down, Move, Up.

UI/Click is a pass-through action bound to <Touchscreen>/touch*/press, and a touch's press control reads its state from the touch phase. When the phase changes from Began to Moved, the press value stays 1 but the action is performed again, and InputSystemProvider dispatched a second ButtonPressed.

The provider now only dispatches a button event when the pressed state of an input changes:

  • Presses are tracked per binding and control, so each finger is tracked on its own. A composite part is tracked as its composite, since parts report the whole composite's value.
  • A release that happens while the click action is disabled never reaches the callback. Update drops tracked presses that the action no longer evaluates as pressed, or whose device was removed, so they don't swallow the next press.

Testing status & QA

Added InputForUITests for touch drags, two fingers, two touchscreens, releases while the UI map is disabled, and click bindings with processors and composites. Ran locally in 6000.0.51f1 batchmode, PlayMode, InputForUITests:

  • With the fix: 71 passed.
  • Without the fix: 6 failed, including TouchDrag_DispatchesOneButtonPressedAndOneButtonReleased and TwoFingerDrag_DispatchesButtonEventsForEachFinger.

I haven't run the full suites locally.

Overall Product Risks

  • Complexity: Low
  • Halo Effect: Medium, every pointer button event from the Input System to UI Toolkit goes through this check, including mouse and pen.

Comments to reviewers

  • The code is the same as the Editor fix, except Unity.InputSystem.ForUI now allows unsafe code. The provider reads the callback's binding state, and in the Editor the package is built with unsafe code allowed, so the fix didn't need it there.
  • A touch's press control notifies listeners on any phase change even when the press value doesn't change. That could be worth a look on its own, but this PR doesn't change it.

Written by Claude Code (AI agent) on behalf of @benoit-alain.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

… extra PointerDownEvent for touch drags

A touch's press control reads its state from the touch phase, so the pass-through UI/Click action is
performed again when the phase changes from Began to Moved. InputSystemProvider dispatched a
ButtonPressed on every callback, so a single-finger drag produced two PointerDownEvents.

The provider now tracks pressed inputs per binding and only dispatches a button event when the
pressed state changes. Presses whose release was missed while the click action was disabled are
dropped in Update.

Unity.InputSystem.ForUI now allows unsafe code, to read the binding state of the callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@u-pr u-pr Bot left a comment

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.

💡 Harness Review

Needs changes

The change filters repeated pressed callbacks and adds focused regression coverage, but the retained press state does not fully account for action lifecycle changes.

Reviewed commit e452b5b

🤖 Helpful? 👍/👎

bindingIndex = ctx.bindingIndex,
control = ctx.control,
};
if (!m_PressedInputs.TryAdd(key, pressedInput))

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.

P1

A new press is swallowed when a disabled release and subsequent press occur before the next InputSystemProvider.Update. After delivering a mouse press, disable the UI map, process the release, then re-enable the map and process another press. The disabled release never reaches OnClickPerformed, and enabling an initial-state check skips released controls. Because ForgetReleasedInputs has not observed the release, TryAdd finds the old key and suppresses the new press. Multiple input updates are supported in manual update mode. Reconcile tracked entries across click-action disable and enable transitions. Add a regression test without a provider update between release and repress.

🤖 Helpful? 👍/👎

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the same edge case that was raised and accepted on the Editor PR (unity/unity#130695). It needs a release to be processed while the UI map is disabled, then the map to be re-enabled and pressed again before the provider's next Update. Manual update mode allows several input updates within that window, but the disable and re-enable must still happen between the release and the press. Disabling a pass-through action fires no canceled, so the only hook available is the global InputSystem.onActionChange. Subscribing to it from the always-on provider would add a callback to every phase change of every action in the game, and disable the no-listener early-out. We're accepting this edge case, and keeping the package identical to the Editor fix.

— Written by Claude Code (AI agent) on behalf of @benoit-alain.

if (!m_PressedInputs.TryAdd(key, pressedInput))
return;
}
else if (!m_PressedInputs.Remove(key))

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.

P1

Erasing an earlier click binding while a button is held can suppress its release and leave m_MouseState.ButtonsState pressed. Configure pass-through UI/Click with initial-state checks off and bindings for right then left mouse buttons. Hold left, disable the map, erase binding zero, and re-enable. Binding resolution reuses InputActionState, but the left binding moves from index one to zero. ForgetReleasedInputs drops the saved index-one entry. OnClickPerformed then rejects the release because the index-zero key was never recorded. Re-find saved bindings using their stable InputBinding.id before polling or matching callbacks. Add a held-button binding-erasure regression test.

🤖 Helpful? 👍/👎

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed: re-resolution reuses the InputActionState, so erasing an earlier UI/Click binding shifts the held binding's index. The tracked press is then dropped, and its release is suppressed. The pointer state stays pressed until the next click on that button, which dispatches normally and restores it. Keying presses on InputBinding.id would add a Guid parse per click callback and a search per held press per frame, to cover editing the UI click bindings while one of them is held. We're accepting this edge case. The Editor fix has the same behavior, and the package stays identical to it.

— Written by Claude Code (AI agent) on behalf of @benoit-alain.

@codecov-github-com

codecov-github-com Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff             @@
##           develop    #2502      +/-   ##
===========================================
+ Coverage    78.96%   79.05%   +0.08%     
===========================================
  Files          767      768       +1     
  Lines       140949   141398     +449     
===========================================
+ Hits        111305   111782     +477     
+ Misses       29644    29616      -28     
Flag Coverage Δ
inputsystem_MacOS_6000.0 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.0_project 77.64% <100.00%> (+0.13%) ⬆️
inputsystem_MacOS_6000.3 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.3_project 77.63% <99.64%> (+0.13%) ⬆️
inputsystem_MacOS_6000.6 5.29% <0.00%> (+<0.01%) ⬆️
inputsystem_MacOS_6000.6_project 77.70% <99.64%> (+0.13%) ⬆️
inputsystem_Ubuntu_6000.0 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.0_project 77.55% <100.00%> (+0.13%) ⬆️
inputsystem_Ubuntu_6000.3 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.3_project 77.54% <99.64%> (+0.12%) ⬆️
inputsystem_Ubuntu_6000.6 5.30% <0.00%> (+<0.01%) ⬆️
inputsystem_Ubuntu_6000.6_project 77.61% <99.64%> (+0.13%) ⬆️
inputsystem_Windows_6000.0 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_Windows_6000.0_project 77.76% <100.00%> (+0.13%) ⬆️
inputsystem_Windows_6000.3 5.31% <0.00%> (+<0.01%) ⬆️
inputsystem_Windows_6000.3_project 77.76% <99.64%> (+0.12%) ⬆️
inputsystem_Windows_6000.6 5.29% <0.00%> (+<0.01%) ⬆️
inputsystem_Windows_6000.6_project 77.82% <99.64%> (+0.12%) ⬆️

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

Files with missing lines Coverage Δ
...ssets/Tests/InputSystem/Plugins/InputForUITests.cs 98.24% <100.00%> (+1.05%) ⬆️
...tsystem/InputSystem/Runtime/Actions/InputAction.cs 92.94% <100.00%> (+0.62%) ⬆️
...em/InputSystem/Runtime/Actions/InputActionState.cs 92.77% <ø> (+0.59%) ⬆️
.../Runtime/Plugins/InputForUI/InputSystemProvider.cs 89.64% <100.00%> (+1.06%) ⬆️

... and 5 files with indirect coverage changes

ℹ️ Need help interpreting these results?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant