Skip to content

Conversation

@K-Tone
Copy link
Collaborator

@K-Tone K-Tone commented Jun 5, 2025

Description

This PR fixes a problem where disabling the InputSystemUIInputModule component would reset all the actions, even if they had been priorly set by user.

This started to happen after a fix for another regression landed, where we unassigned all actions from the components OnDisable. I believe this is wrong, since the only thing we really need to be resetting is the default actions asset that shouldn't normally survive re-reentering playmode.

Testing status & QA

Local testing, a new regression test, pending a QA pass

Overall Product Risks

  • Complexity: Low
  • Halo Effect: Low

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.

InputActionState.s_GlobalState.onActionControlsChanged.RemoveCallback(m_OnControlsChangedDelegate);
DisableAllActions();
UnhookActions();
UnassignActions();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

^ This line is very wrong, it results in user data being lost on component deactivation.

@codecov-github-com
Copy link

codecov-github-com bot commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 36.36364% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...InputSystem/Plugins/UI/InputSystemUIInputModule.cs 36.36% 7 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2192      +/-   ##
===========================================
- Coverage    67.78%   67.78%   -0.01%     
===========================================
  Files          367      367              
  Lines        53526    53536      +10     
===========================================
+ Hits         36284    36287       +3     
- Misses       17242    17249       +7     
Flag Coverage Δ
mac_2021.3_pkg 5.41% <0.00%> (-0.01%) ⬇️
mac_2021.3_project 70.42% <36.36%> (-0.02%) ⬇️
mac_2022.3_pkg 5.19% <ø> (ø)
mac_2022.3_project 65.28% <36.36%> (-0.01%) ⬇️
mac_6000.0_pkg 5.20% <ø> (ø)
mac_6000.0_project 67.70% <36.36%> (-0.01%) ⬇️
mac_6000.1_pkg 5.20% <ø> (ø)
mac_6000.1_project 67.70% <36.36%> (-0.01%) ⬇️
mac_6000.2_pkg 5.20% <ø> (ø)
mac_6000.2_project 67.70% <36.36%> (-0.01%) ⬇️
mac_trunk_pkg 5.20% <ø> (ø)
mac_trunk_project 67.70% <36.36%> (-0.01%) ⬇️
win_2021.3_pkg 5.41% <0.00%> (-0.01%) ⬇️
win_2021.3_project 70.49% <36.36%> (-0.02%) ⬇️
win_2022.3_pkg 5.19% <ø> (ø)
win_2022.3_project 65.36% <36.36%> (-0.01%) ⬇️
win_6000.0_pkg 5.20% <ø> (ø)
win_6000.0_project 67.77% <36.36%> (-0.01%) ⬇️
win_6000.1_pkg 5.20% <ø> (ø)
win_6000.1_project 67.77% <36.36%> (-0.01%) ⬇️
win_6000.2_pkg 5.20% <ø> (ø)
win_6000.2_project 67.77% <36.36%> (-0.01%) ⬇️
win_trunk_pkg 5.20% <ø> (ø)
win_trunk_project 67.77% <36.36%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...InputSystem/Plugins/UI/InputSystemUIInputModule.cs 93.17% <36.36%> (-0.59%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@K-Tone K-Tone changed the title reset the default actions static field during scene load to fix it ha… FIX: disabling the InputSystemUIInputModule resets all actions to None Jun 5, 2025
@K-Tone K-Tone changed the title FIX: disabling the InputSystemUIInputModule resets all actions to None FIX: disabling the InputSystemUIInputModule component resets all actions to None Jun 5, 2025
@K-Tone K-Tone requested a review from Copilot June 6, 2025 09:18

This comment was marked as outdated.

@K-Tone
Copy link
Collaborator Author

K-Tone commented Jun 6, 2025

As to the catches by Copilot:

(1) This is fine. Historically, we've only had UnassignActions since the beginning of the year, and that was a mistake, so I think future maintainers don't need to know we made that mistake and corrected it quickly

(2) There is a short, but to the point comment actually. Not sure I'd like to expand it further.

@K-Tone K-Tone requested review from Pauliusd01 and ekcoh June 6, 2025 10:12
Copy link
Collaborator

@Pauliusd01 Pauliusd01 left a comment

Choose a reason for hiding this comment

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

Found an issue with the UI default actions getting added in after a scene load. Steps are: Open our main repo as a unity project -> top dropdown QA Tools -> Add all core samples / open core scene -> import the textmeshpro essentials if needed -> make sure the event system is set to use a project wide actions asset if it isn't already -> enter play mode and observe the action count -> pick anything from the scene loader -> esc -> return to scene picker and observe the action count again. This does not reproduce in Develop

06.06.2025.-.Unity.197.mp4

@K-Tone
Copy link
Collaborator Author

K-Tone commented Jun 25, 2025

Hey @Pauliusd01, could you try it again please? With this new patch, I tried:

(1) With actions asset set before play mode

  • Disabling component doesn't lead to all actions lost any more
  • Entering playmode and loading the project-wide test scene and navigating the menu doesn't duplicate actions

(2) With no actions asset set before play mode

  • Entering playmode sets the default actions correctly
  • Disabling domain reload and entering play mode twice doesn't result in exception

Note that when you enter play mode with InputSystemUIInputModule that had no actions asset assigned it results in us creating some default actions asset behind the scenes and using it to assign all actions. Disabling this component results in us destroying the default asset, and thus the actions get unassigned as well, so you do get "None" in this case, which I guess is kinda by design (though unfortunate). Enabling it back will restore defaults. If I were to redesign this component from scratch, I would make an explicit checkbox in the component called "Use defaults", and in this case I would hide all the actions, so that the user doesn't get confused by what is going on behind the scenes. This would also simplify code a little bit.

@Pauliusd01 Pauliusd01 self-requested a review June 25, 2025 08:42
UnhookActions();
UnassignActions();

// In the case we've been initialialised with default actions, we want to unalloc them
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We want to do this because if we don't dealloc them, then no one would

{
if (defaultActions != null)
{
defaultActions.Dispose();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess, calling Dispose is just to stay on the safe side since the only data default actions stores is a ref to ScriptableObject that won't survive even with domain reload off. It will be in this intermediate state though, where its native data is gone but the instance is not null until the next gc run (however you'll see it as "null" in debugger, and ==null will be true as well, thanks to Unity's Equals overload for all Object descendants).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this comment imply that it should be Object.ReferenceEquals(null, defaultActions) in if statement above? If its disposable, yes it should be disposed, even if the implementation would do nothing IMO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think I wasn't clear, pardon. DefaultActions is fine to check for null like above since it's not destroyed natively. What is in the intermediate state happens to be aggregated in defaultActions (DefaultActions has a ref to ScriptableObject, so it's the ScriptableObject would have to be checked with ReferenceEquals if we needed to, but we don't).

@K-Tone K-Tone marked this pull request as ready for review June 25, 2025 08:59
@K-Tone K-Tone force-pushed the anthony/isxb-1493-deactivation-resets-actions branch from bb42698 to e4eba87 Compare June 25, 2025 08:59
@K-Tone K-Tone requested a review from Copilot June 25, 2025 15:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue where disabling the InputSystemUIInputModule component unintentionally resets user-assigned actions by refining the reset logic for default actions.

  • Introduces a static ResetDefaultActions method to dispose of lingering static default actions across domain reloads.
  • Modifies OnDisable to only unassign default actions when they match the current actions asset.
  • Adds a regression Unity test to verify user actions persist and updates a test description in the editor tests for clarity.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs Added ResetDefaultActions method with proper disposal logic and refined OnDisable unassignment for default actions.
Packages/com.unity.inputsystem/CHANGELOG.md Added a changelog entry summarizing the fix.
Assets/Tests/InputSystem/Plugins/UITests.InputModuleTests.cs Added a new regression test ensuring disabling does not reset user actions.
Assets/Tests/InputSystem.Editor/ProjectWideInputActionsEditorTests.cs Updated test description for improved grammar.

Copy link
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.

Nice and tidy, looks good to me, great you added a test for the regression. Only a single comment/question regarding the null check.

}

[UnityTest]
[Description("Regression test for https://jira.unity3d.com/browse/ISXB-1493")]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great you added a specific test for the regression

{
if (defaultActions != null)
{
defaultActions.Dispose();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this comment imply that it should be Object.ReferenceEquals(null, defaultActions) in if statement above? If its disposable, yes it should be disposed, even if the implementation would do nothing IMO.

@ekcoh
Copy link
Collaborator

ekcoh commented Jun 25, 2025

@K-Tone Looks like you need to rerun the formatter on this branch before CI will be happier. Other failures look like instabilities.

@K-Tone K-Tone force-pushed the anthony/isxb-1493-deactivation-resets-actions branch from eb2a2b1 to 5c996c0 Compare June 26, 2025 10:31
@K-Tone K-Tone merged commit 4f6aca6 into develop Jun 27, 2025
131 checks passed
@K-Tone K-Tone deleted the anthony/isxb-1493-deactivation-resets-actions branch June 27, 2025 08:19
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.

4 participants