Skip to content

Conversation

jfreire-unity
Copy link
Collaborator

@jfreire-unity jfreire-unity commented Sep 11, 2025

Description

Proposed solution to fix ISXB-1671.

The bug reports a UITK event that shouldn't be triggered. This ocurrs due to a InputSystemProvider UI Click action being performed once the Editor is in play-mode and we select Game view tab when previously in Scene View.

The action that is triggered provides the wrong mouse position. Essentially, an action is being performed for the mouse click/position that happened while out of focus in the Editor and triggered the focus regain. However, when InputManager.OnUpdate() is called, it assumes the game already is in focus, so there was no way to know if an event was triggered out of focus or not.

The proposed solution is to filter and discard the events that happened immediately before focus was regained, by checking if they were received before the focus regain. In the diagram below, essentially we are discarding the "ofending" event - in red - that triggered an Input Action, which would then dispatch a UITK event through InputSystemProvider.

image

Unrelated changes to bug-fix

I also did a small refactoring to put some conditions in their own functions so that can be easier to read through InputManager.OnUpdate. This is just a personal preference as it has been historically complicated to reason about all the conditions we have. This is still not perfect, but I hope it's a small improvement for others as well.

If you want, you can have a look of the commit which contains the fix changes, 6157498. This doesn't have any refactoring yet and is easier to reason about.

Testing status & QA

Please describe the testing already done by you and what testing you request/recommend QA to execute. If you used or created any testing project please link them here too for QA.

Overall Product Risks

Please rate the potential complexity and halo effect from low to high for the reviewers. Note down potential risks to specific Editor branches if any.

  • Complexity:
  • Halo Effect:

Comments to reviewers

Please describe any additional information such as what to focus on, or historical info for the reviewers.

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.

After merge:

  • Create forward/backward port if needed. If you are blocked from creating a forward port now please add a task to ISX-1444.

@codecov-github-com
Copy link

codecov-github-com bot commented Sep 11, 2025

Codecov Report

Attention: Patch coverage is 94.73684% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../com.unity.inputsystem/InputSystem/InputManager.cs 94.73% 3 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2234      +/-   ##
===========================================
+ Coverage    68.17%   68.18%   +0.01%     
===========================================
  Files          367      367              
  Lines        53668    53714      +46     
===========================================
+ Hits         36587    36627      +40     
- Misses       17081    17087       +6     
Flag Coverage Δ
linux_2021.3_pkg 5.53% <70.17%> (+0.06%) ⬆️
linux_2021.3_project 70.43% <94.73%> (+0.02%) ⬆️
linux_2022.3_pkg 5.30% <70.17%> (+0.06%) ⬆️
linux_2022.3_project 65.28% <94.73%> (+0.02%) ⬆️
linux_6000.0_pkg 5.31% <70.17%> (+0.06%) ⬆️
linux_6000.0_project 68.09% <94.73%> (+0.03%) ⬆️
linux_6000.2_pkg 5.31% <70.17%> (+0.06%) ⬆️
linux_6000.2_project 68.08% <94.73%> (+0.02%) ⬆️
linux_trunk_pkg 5.31% <70.17%> (+0.06%) ⬆️
linux_trunk_project 68.08% <94.73%> (+0.02%) ⬆️
mac_2021.3_pkg 5.53% <70.17%> (+0.06%) ⬆️
mac_2021.3_project 70.44% <94.73%> (+0.02%) ⬆️
mac_2022.3_pkg 5.30% <70.17%> (+0.06%) ⬆️
mac_2022.3_project 65.30% <94.73%> (+0.03%) ⬆️
mac_6000.0_pkg 5.30% <70.17%> (+0.06%) ⬆️
mac_6000.0_project 68.11% <94.73%> (+0.02%) ⬆️
mac_6000.2_pkg 5.30% <70.17%> (+0.06%) ⬆️
mac_6000.2_project 68.10% <94.73%> (+0.02%) ⬆️
mac_trunk_pkg 5.31% <70.17%> (+0.06%) ⬆️
mac_trunk_project 68.10% <94.73%> (+0.01%) ⬆️
win_2021.3_pkg 5.53% <70.17%> (+0.06%) ⬆️
win_2021.3_project 70.52% <94.73%> (+0.02%) ⬆️
win_2022.3_pkg 5.30% <70.17%> (+0.06%) ⬆️
win_2022.3_project 65.38% <94.73%> (+0.03%) ⬆️
win_6000.0_pkg 5.31% <70.17%> (+0.06%) ⬆️
win_6000.0_project 68.18% <94.73%> (+0.02%) ⬆️
win_6000.2_pkg 5.31% <70.17%> (+0.06%) ⬆️
win_6000.2_project 68.18% <94.73%> (+0.03%) ⬆️
win_trunk_pkg 5.31% <70.17%> (+0.06%) ⬆️
win_trunk_project 68.18% <94.73%> (+0.02%) ⬆️

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

Files with missing lines Coverage Δ
.../com.unity.inputsystem/InputSystem/InputManager.cs 89.06% <94.73%> (+0.28%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jfreire-unity jfreire-unity force-pushed the isxb-1671-outoffocus-events-trigger-actions branch 2 times, most recently from dc01440 to f21ad55 Compare September 11, 2025 13:08
@jfreire-unity jfreire-unity force-pushed the isxb-1671-outoffocus-events-trigger-actions branch from f21ad55 to 6157498 Compare September 11, 2025 13:11
It's tested against all background behavior settings.
The goal is here is to make those conditions self contained in "chunks" so that we can slightly reduce the cognitive load when reading through the OnUpdate() function.

This is a personal preference and others in the team might disagree with these changes.
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