Skip to content

FIX: Add test and fix for multiple touchscreen input bug.#2434

Open
Darren-Kelly-Unity wants to merge 2 commits into
developfrom
bugfix/UUM-112247-multiple-touchscreens-incorrect-input
Open

FIX: Add test and fix for multiple touchscreen input bug.#2434
Darren-Kelly-Unity wants to merge 2 commits into
developfrom
bugfix/UUM-112247-multiple-touchscreens-incorrect-input

Conversation

@Darren-Kelly-Unity

@Darren-Kelly-Unity Darren-Kelly-Unity commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Purpose of this PR

Fixes a bug (IN-108611) where an ongoing touch on one physical touchscreen could be incorrectly updated by touch events originating from a second physical touchscreen, when both screens reported the same touchId. The root cause was that three touch-matching code paths in Touchscreen.cs identified touches by touchId alone, ignoring displayIndex.

Release Notes

[IN-108611] Input System — Bug Fixes

  • Fixed: Touch events from one physical touchscreen incorrectly updating touch state on another touchscreen when both screens reported the same touchId.

Functional Testing status

  • Automated: New regression test Devices_TouchMoveOnSecondDisplay_DoesNotUpdateTouchOnFirstDisplay added to TouchscreenMultiDisplayTests.cs, covering the exact failure sequence (two Began events with the same touchId on different displayIndex values, followed by a Moved from one screen verifying the other is untouched).
  • Manual: Reproducible via two physical touchscreen monitors per the original bug report steps (hold finger on screen 1, swipe on screen 2). This hasn't been tested by me manually due to no device, we need QA to test this.

Performance Testing Status

No performance impact. The three changed comparisons each add a single byte comparison (displayIndex) to an existing conditional — no additional allocations, iterations, or data structure changes.

Overall Product Risks

Technical Risk: 1 — Self-contained fix to three closely related conditions in one file. Behaviour change is additive (stricter matching); single-screen setups are entirely unaffected since displayIndex will always match itself.

Halo Effect: 1 — Could affect any code path relying on Touchscreen with multi-display touch input, but the existing behaviour in those paths was already incorrect.

Class diagram

Changes analysed from origin/develop...HEAD

Class diagram
classDiagram
    class Touchscreen {
        «modified» OnStateEvent()
        «modified» GetCurrentValueAsObject()
        «modified» MergeForward()
    }
Loading

@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.

May require changes

The PR addresses the touch ID collision bug effectively, but the introduced strict matching causes a regression for cross-display simulated touches.

🤖 Helpful? 👍/👎

@codecov-github-com

codecov-github-com Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

@@             Coverage Diff              @@
##           develop    #2434       +/-   ##
============================================
+ Coverage    58.58%   79.01%   +20.43%     
============================================
  Files          738      766       +28     
  Lines       135831   140369     +4538     
============================================
+ Hits         79570   110917    +31347     
+ Misses       56261    29452    -26809     
Flag Coverage Δ
inputsystem_MacOS_6000.0 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.0_project 77.47% <100.00%> (+0.22%) ⬆️
inputsystem_MacOS_6000.3 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.3_project 77.47% <100.00%> (+0.25%) ⬆️
inputsystem_MacOS_6000.4 5.32% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.4_project 77.48% <100.00%> (+0.25%) ⬆️
inputsystem_MacOS_6000.5 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.5_project 77.52% <100.00%> (+0.25%) ⬆️
inputsystem_MacOS_6000.6 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.6_project 77.52% <100.00%> (+0.25%) ⬆️
inputsystem_Ubuntu_6000.0 5.32% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.0_project 77.38% <100.00%> (+0.23%) ⬆️
inputsystem_Ubuntu_6000.3 5.32% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.3_project 77.38% <100.00%> (+0.25%) ⬆️
inputsystem_Ubuntu_6000.4 5.32% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.4_project 77.39% <100.00%> (+0.25%) ⬆️
inputsystem_Ubuntu_6000.5 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.5_project 77.42% <100.00%> (+0.25%) ⬆️
inputsystem_Ubuntu_6000.6 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.6_project 77.43% <100.00%> (+0.26%) ⬆️
inputsystem_Windows_6000.0 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.0_project 77.60% <100.00%> (+0.22%) ⬆️
inputsystem_Windows_6000.3 5.31% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.3_project 77.59% <100.00%> (+0.25%) ⬆️
inputsystem_Windows_6000.4 5.32% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.4_project 77.60% <100.00%> (+0.25%) ⬆️
inputsystem_Windows_6000.5 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.5_project 77.65% <100.00%> (+0.25%) ⬆️
inputsystem_Windows_6000.6 5.30% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.6_project 77.65% <100.00%> (+0.25%) ⬆️

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

Files with missing lines Coverage Δ
.../Tests/InputSystem/TouchscreenMultiDisplayTests.cs 100.00% <100.00%> (ø)
...tsystem/InputSystem/Runtime/Devices/Touchscreen.cs 91.26% <100.00%> (+90.96%) ⬆️
...m/Runtime/Plugins/EnhancedTouch/TouchSimulation.cs 90.64% <100.00%> (+88.63%) ⬆️

... and 277 files with indirect coverage changes

ℹ️ Need help interpreting these results?

@Darren-Kelly-Unity Darren-Kelly-Unity changed the title Add test and fix for multiple touchscreen input bug. FIX: Add test and fix for multiple touchscreen input bug. Jun 12, 2026

@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.

Perfect

Solid fix for multi-display touch matching with comprehensive automated test coverage.

🤖 Helpful? 👍/👎

@Pauliusd01

Copy link
Copy Markdown
Collaborator

/test_plan

@u-pr

u-pr Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Test Plan

  • Test plan approved by PR author
  • Test execution in progress
  • Test execution complete
  • Ready for merge

Summary of Changes & Risk Assessment

Summary of Changes

This PR fixes a bug (IN-108611) where touch events from different physical touchscreens could conflict if they shared the same touchId. The fix ensures that the Input System uses both touchId and displayIndex to uniquely identify an ongoing touch. Changes are made to the core Touchscreen logic, event merging, and the TouchSimulation plugin.

Risk Assessment

  • High Risk Areas: None identified.
  • Medium Risk Areas: Core touch input processing (Touchscreen.cs), Touch simulation (TouchSimulation.cs).
  • Low Risk Areas: Single-display touch setups (where displayIndex is constant).

Test Scenarios

Functional Testing

  • Multi-Display Separation: Run the new regression test Devices_TouchMoveOnSecondDisplay_DoesNotUpdateTouchOnFirstDisplay in TouchscreenMultiDisplayTests.cs:L21 to verify that a move on Screen B doesn't affect a held touch on Screen A with the same ID.
  • Touch Simulation: Verify that TouchSimulation correctly tracks display indices by simulating touches on different displays and checking that m_TouchDisplayIndices stores the correct values (TouchSimulation.cs:L312).

Regression Testing

  • Single Display Consistency: Verify standard touch behavior on a single-display setup (Android/iOS or single monitor Windows/macOS). Ensure displayIndex (defaulting to 0) does not interfere with standard ID matching.
  • Event Merging: Verify that multiple Moved events for the same finger on the same display still merge correctly in MergeForward, while events from different displays do not merge (Touchscreen.cs:L1005).
  • Primary Touch Tracking: Ensure the "Primary Touch" logic in OnStateEvent still correctly identifies and updates the primary touch slot when displayIndex is involved (Touchscreen.cs:L697).
🔍 Regression Deep Dive (additional risks identified)
  • State Offset Mapping: Verify GetStateOffsetForEvent returns the correct offset for events when multiple displays are active. This affects how the Editor/Internal tools read state from events (Touchscreen.cs:L918).
  • EnhancedTouch API: Verify that UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches correctly reports separate touches for the multi-display scenario described in the PR.

Edge Cases

  • Display Index Overflow: Validate behavior if a platform reports a displayIndex larger than 255 (the TouchState.displayIndex is a byte).
  • Rapid Display Reassignment: Test behavior if a touch starts on displayIndex 0 but a subsequent event for the same touchId arrives with a different displayIndex (should be treated as a new touch or ignored for the previous slot).

💡 This test plan updates automatically when /test_plan is run on new commits. If you have any feedback, please reach out in #ai-qa


🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@Pauliusd01

Copy link
Copy Markdown
Collaborator

I have no access to two pc touchscreens so I will look for someone who could help.

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.

2 participants