Skip to content

FIX: Avoid disabling project-wide actions on shutdown#2346

Open
AswinRajGopal wants to merge 6 commits intodevelopfrom
uum-134130/fix-project-wide-action-onshutdown
Open

FIX: Avoid disabling project-wide actions on shutdown#2346
AswinRajGopal wants to merge 6 commits intodevelopfrom
uum-134130/fix-project-wide-action-onshutdown

Conversation

@AswinRajGopal
Copy link
Copy Markdown
Collaborator

@AswinRajGopal AswinRajGopal commented Feb 17, 2026

Description

case: https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-134130

Bug:
UI Toolkit now destroys its internal objects when there is no UI left in the scene, so InputSystemProvider.Shutdown() can run during play. During shutdown we unregister the UI actions, but the old code was
managing the whole action asset. With project-wide actions (InputSystem.actions), that meant we could affect input outside UI. With the default internal asset, not cleaning up at all could leave the UI map
enabled longer than intended.

Fix:
Scope the lifecycle to the UI action map only. On registration, InputSystemProvider now makes sure the UI map is enabled. On unregister/shutdown, it disables only that UI map, and only if this provider
enabled it. This avoids changing the enabled state of unrelated maps in InputSystem.actions while still cleaning up the default/internal UI actions correctly.

Testing status & QA

Added new test.
Verified manually using repro project.

Overall Product Risks

  • Complexity: Low
  • Halo Effect: Low

Comments to 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.

@u-pr
Copy link
Copy Markdown
Contributor

u-pr bot commented Feb 17, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

UUM-134130 - Fully compliant

Compliant requirements:

  • The PR prevents disabling the m_InputActionAsset on shutdown if it matches the global InputSystem.actions.
⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪

The PR consists of a single logical check added to one method and a corresponding unit test. The scope is small and well-defined.
🏅 Score: 95

The fix correctly addresses the reported issue by checking against the project-wide actions before disabling. The code is clean, and a regression test is included.
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Test State Cleanup

The test modifies the static state InputSystem.s_Manager.actions (line 111) but does not explicitly reset it to null or its previous value. Although the asset is destroyed (line 119), leaving a reference to a destroyed object in a static manager could potentially affect subsequent tests depending on the test fixture's teardown logic.

InputSystem.s_Manager.actions = asset;

m_InputSystemProvider.Initialize();
Assert.That(asset.enabled, Is.True, "Project-wide actions should be enabled by provider initialization.");

m_InputSystemProvider.Shutdown();
Assert.That(asset.enabled, Is.True, "Project-wide actions must remain enabled after provider shutdown.");

Object.DestroyImmediate(asset);
  • Update review

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

@u-pr
Copy link
Copy Markdown
Contributor

u-pr bot commented Feb 17, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Restore global state after test execution

The test modifies the global static state InputSystem.s_Manager.actions without
restoring it, which can cause side effects or failures in subsequent tests. Wrap the
test logic in a try-finally block to ensure that the original state is restored and
the temporary asset is properly destroyed, even if an assertion fails.

Assets/Tests/InputSystem/Plugins/InputForUITests.cs [111-119]

-InputSystem.s_Manager.actions = asset;
+var originalActions = InputSystem.s_Manager.actions;
+try
+{
+    InputSystem.s_Manager.actions = asset;
 
-m_InputSystemProvider.Initialize();
-Assert.That(asset.enabled, Is.True, "Project-wide actions should be enabled by provider initialization.");
+    m_InputSystemProvider.Initialize();
+    Assert.That(asset.enabled, Is.True, "Project-wide actions should be enabled by provider initialization.");
 
-m_InputSystemProvider.Shutdown();
-Assert.That(asset.enabled, Is.True, "Project-wide actions must remain enabled after provider shutdown.");
+    m_InputSystemProvider.Shutdown();
+    Assert.That(asset.enabled, Is.True, "Project-wide actions must remain enabled after provider shutdown.");
+}
+finally
+{
+    InputSystem.s_Manager.actions = originalActions;
+    Object.DestroyImmediate(asset);
+}
 
-Object.DestroyImmediate(asset);
-
Suggestion importance[1-10]: 8

__

Why: The test modifies the global static state InputSystem.s_Manager.actions. Without a try-finally block, an assertion failure would prevent the restoration of the original state and the destruction of the created asset, potentially causing test pollution and side effects in subsequent tests.

Medium
  • More suggestions

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

@codecov-github-com
Copy link
Copy Markdown

codecov-github-com bot commented Feb 17, 2026

Codecov Report

All modified and coverable lines are covered by tests ✅

@@            Coverage Diff            @@
##           develop    #2346    +/-   ##
=========================================
  Coverage    77.90%   77.91%            
=========================================
  Files          476      482     +6     
  Lines        97613    97780   +167     
=========================================
+ Hits         76048    76187   +139     
- Misses       21565    21593    +28     
Flag Coverage Δ
inputsystem_MacOS_2022.3_project 75.35% <ø> (-0.04%) ⬇️
inputsystem_MacOS_6000.0 5.27% <0.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.0_project 77.26% <100.00%> (-0.03%) ⬇️
inputsystem_MacOS_6000.3 5.27% <0.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.3_project 77.26% <100.00%> (-0.03%) ⬇️
inputsystem_MacOS_6000.4 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.4_project 77.27% <100.00%> (-0.03%) ⬇️
inputsystem_MacOS_6000.5 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.5_project 77.27% <100.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.6 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_MacOS_6000.6_project 77.27% <100.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_2022.3_project 75.15% <ø> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.0 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.0_project 77.06% <100.00%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.3 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.3_project 77.06% <100.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.4 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.4_project 77.08% <100.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.5 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.5_project 77.07% <100.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.6 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Ubuntu_6000.6_project 77.07% <100.00%> (-0.04%) ⬇️
inputsystem_Windows_2022.3 5.30% <ø> (-0.23%) ⬇️
inputsystem_Windows_2022.3_project 75.48% <ø> (-0.05%) ⬇️
inputsystem_Windows_6000.0 5.27% <0.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.0_project 77.39% <100.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.3 5.27% <0.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.3_project 77.38% <100.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.4 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.4_project 77.39% <100.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.5 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.5_project 77.39% <100.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.6 5.28% <0.00%> (-0.04%) ⬇️
inputsystem_Windows_6000.6_project 77.39% <100.00%> (-0.04%) ⬇️

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 96.91% <100.00%> (+0.20%) ⬆️
...utSystem/Plugins/InputForUI/InputSystemProvider.cs 86.64% <100.00%> (+0.03%) ⬆️

... and 8 files with indirect coverage changes

ℹ️ Need help interpreting these results?

@AswinRajGopal AswinRajGopal removed the request for review from Pauliusd01 February 17, 2026 11:43
UnregisterAction(ref m_ScrollWheelAction, OnScrollWheelPerformed);

if (m_InputActionAsset != null)
if (m_InputActionAsset != null && m_InputActionAsset != InputSystem.actions)
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.

Do we actually have to disable the actions? I'm not a huge fan of disabling this for a particular asset, like project wide actions. I also think the logic we implemented in the past might not be the most correct.

I believe we should always make sure that the UI action map is enabled when registering the actions. Do you know what's the impact of not disabling this asset for a normal asset?

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.

@jfreire-unity Thanks for the review, I agree that the current change only addresses the reported bug. I’ll improve the fix so that we explicitly ensure the UI action map is enabled when registering actions, and on unregister we only clean up state owned by the provider instead of disabling shared asset state.

@Pauliusd01
Copy link
Copy Markdown
Collaborator

/test_plan

@u-pr
Copy link
Copy Markdown
Contributor

u-pr bot commented Mar 30, 2026

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 where the InputSystemProvider would disable the entire InputActionAsset upon shutdown (e.g., when UI Toolkit objects are destroyed in-scene). This was problematic for project-wide actions (InputSystem.actions), as it would kill all input globally. The fix scopes the enable/disable lifecycle strictly to the "UI" action map and ensures the provider only disables the map if it was responsible for enabling it.

Risk Assessment

  • High Risk Areas: None identified.
  • Medium Risk Areas: Action map state management (ensuring maps aren't accidentally left enabled or disabled in complex UI transition scenarios).
  • Low Risk Areas: Unit test cleanup and static state management in tests.

Test Scenarios

Functional Testing

  • Project-wide Asset Preservation: Verify that when InputSystem.actions is assigned, calling Shutdown() on the provider does not call Disable() on the asset itself.
  • UI Map Specific Lifecycle: Verify that only the map named "UI" is toggled by the provider. If an asset has a "Gameplay" map and a "UI" map, "Gameplay" should remain untouched.
  • Conditional Disable Logic:
    • Case A: UI Map is already enabled by the user -> Provider Init -> Provider Shutdown -> UI Map stays enabled.
    • Case B: UI Map is disabled -> Provider Init (enables it) -> Provider Shutdown -> UI Map is disabled.

Regression Testing

  • Default Action Path: Verify that when no custom asset is used (default internal actions), the UI maps are still correctly enabled for standard UITK usage.
  • Test Suite Stability: Run InputForUITests.cs:L33 to ensure the new Shutdown_DoesNotDisableProjectWideActionsAsset test passes and doesn't pollute global state.
🔍 Regression Deep Dive (additional risks identified)
  • Manual UnregisterActions call: Verify that if InputSystemProvider.cs:L655 is called manually via internal APIs, the m_UIActionMap reference is correctly cleared to null to avoid leaking references to destroyed assets.
  • Missing "UI" Map: Verify behavior when the assigned InputActionAsset does not contain a map named "UI" (should fail gracefully/not throw null ref).

Edge Cases

  • Asset Swapping: If InputSystem.actions is changed after the provider has initialized, verify that Shutdown still behaves safely (the logic in RegisterActions captures the state of the asset active at that moment).

💡 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

Pauliusd01 commented Mar 30, 2026

I'm not entirely sure what the expected outcome should be. Is it expected that most actions including UI remain active when deleting the UI object? What about this one in the screenshot, what makes it special and why is it the only one that gets removed?
image

@AswinRajGopal
Copy link
Copy Markdown
Collaborator Author

I'm not entirely sure what the expected outcome should be. Is it expected that most actions including UI remain active when deleting the UI object? What about this one in the screenshot, what makes it special and why is it the only one that gets removed?

Hi @Pauliusd01 nextPreviousAction (no Asset) is the exception because it is not part of the project asset. The code creates it temporarily just for this UI provider and removes it again when the provider goes away. That is why it is the only one that disappears. @jfreire-unity Please correct me if I'm wrong.

@jfreire-unity
Copy link
Copy Markdown
Collaborator

Sorry I'll try to have a look at this in the next couple of days. Need to "load the context" of this area to make sure we're not introducing any other regression

@jfreire-unity
Copy link
Copy Markdown
Collaborator

/crc

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 has identified several significant issues that need to be addressed. The current implementation introduces a regression risk with a potential ArgumentException when custom assets are used. Additionally, there is a logic discrepancy in the fix itself that results in disabling portions of the project-wide action asset, which will likely cause the newly added test case to fail. Some minor improvements to test code consistency and maintenance are also recommended.

🤖 Helpful? 👍/👎

m_InputActionAsset.Enable();
// Only touch the UI map so we don't change the enabled state of unrelated maps.
m_UIActionMap = m_InputActionAsset?.FindActionMap("UI", true);
m_ShouldDisableUIActionMapOnUnregister = m_UIActionMap != null && !m_UIActionMap.enabled;
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
This call will throw an ArgumentException if the m_InputActionAsset does not contain a map named "UI". This is a regression for scenarios where a user provides a custom InputActionAsset (via InputSystem.actions) that uses different map names (e.g., "Default", "GameUI", etc.).

Additionally, if the user's UI actions are located in a map with a different name, only enabling the "UI" map will result in the integration failing to work because the relevant actions will remain disabled. The previous implementation was safer as it enabled the entire asset when a user-provided asset was detected.

Suggested change
m_ShouldDisableUIActionMapOnUnregister = m_UIActionMap != null && !m_UIActionMap.enabled;
m_UIActionMap = m_InputActionAsset?.FindActionMap("UI", false);

🤖 Helpful? 👍/👎

if (m_InputActionAsset != null)
m_InputActionAsset.Disable();
if (m_ShouldDisableUIActionMapOnUnregister && m_UIActionMap != null)
m_UIActionMap.Disable();
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.

medium
There is a logic mismatch between this implementation and the newly added test case Shutdown_DoesNotDisableProjectWideActionsAsset.

In the test, the asset is not enabled initially. RegisterActions will set m_ShouldDisableUIActionMapOnUnregister to true and enable the "UI" map. When UnregisterActions is called, it will then call m_UIActionMap.Disable(). Since "UI" is the only map in the test asset, asset.enabled will become false, causing the assertion at line 121 in InputForUITests.cs to fail.

If the intention is to prevent side-effects on the project-wide asset, you should consider skipping the Disable() call if m_InputActionAsset is the global InputSystem.actions asset.

🤖 Helpful? 👍/👎


EventProvider.ClearMockProvider();
m_ClearedMockProvider = true;
Assert.That(asset.enabled, Is.True, "Project-wide actions must remain enabled after provider shutdown.");
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.

medium
Based on the implementation in InputSystemProvider.UnregisterActions, this assertion will likely fail.

If the provider was responsible for enabling the "UI" map (which it will be here since the asset is newly created and its maps are disabled by default), it will disable that map during shutdown. Since no other maps are enabled in this test asset, asset.enabled will return false after the provider is cleared.

🤖 Helpful? 👍/👎

uiMap.AddAction("ScrollWheel", InputActionType.PassThrough, "<Mouse>/scroll");
asset.AddActionMap(uiMap);

InputSystem.s_Manager.actions = asset;
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
For better maintainability and consistency with the rest of the test class, consider using the public InputSystem.actions property instead of the internal s_Manager field. This aligns with the access pattern used in the Setup method.

Suggested change
InputSystem.s_Manager.actions = asset;
InputSystem.actions = asset;

🤖 Helpful? 👍/👎

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.

3 participants