Skip to content

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

Open
AswinRajGopal wants to merge 18 commits into
developfrom
uum-134130/fix-project-wide-action-onshutdown
Open

FIX: Avoid disabling project-wide actions on shutdown#2346
AswinRajGopal wants to merge 18 commits into
developfrom
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 🔍

(Review updated until commit 15e20a1)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

UUM-134130 - PR Code Verified

Compliant requirements:

  • Deleting a GameObject with a UIDocument component during Play mode must not remove project-wide input actions.
  • The fix should cover the UI Toolkit shutdown path that now runs when no UI is left in the scene.
  • Add or update test coverage for this regression.

Requires further human verification:

  • After deleting the UIDocument object, the Input Debugger Actions list should remain unchanged.
  • Verify the repro steps manually in the Editor, including the stated Windows 11 scenario.
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪

Small, localized changes with added tests make this fairly quick to review, though the lifecycle edge cases need some careful reasoning.

🏅 Score: 84

The fix is targeted and tested, but it appears to leave stale enabled state behind when switching away from a project-wide action asset at runtime.

🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

State leak

When the provider enables a previously disabled UI map from InputSystem.actions, it never marks that map for cleanup because the asset is project-wide. If InputSystem.actions is later reassigned or otherwise triggers OnActionsChange(), the provider detaches from the old asset without restoring its original disabled state, so the old UI map can stay enabled unexpectedly.

// For provider-owned assets we are responsible for cleanup on shutdown.
// For project-wide actions the play-mode lifecycle manages the asset, so
// leave it as-is when the provider goes away.
if (m_InputActionAsset != InputSystem.actions)
    m_ShouldDisableUIActionMapOnUnregister = true;
📜 Additional Context from files
Packages/.../InputForUI/InputSystemProvider.cs - Lines 77-127

Provides the necessary context for the Initialize and Shutdown lifecycle of InputSystemProvider, where RegisterActions and UnregisterActions are called, confirming when the UI action map is enabled and disabled.

Packages/.../InputForUI/InputSystemProvider.cs - Lines 656-694

Contains SelectInputActionAsset(), which determines whether m_InputActionAsset resolves to InputSystem.actions (project-wide actions) or the default asset, directly validating the condition m_InputActionAsset != InputSystem.actions introduced in this PR.

  • 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    78.13%   78.83%   +0.70%     
===========================================
  Files          483      760     +277     
  Lines        98770   138592   +39822     
===========================================
+ Hits         77169   109257   +32088     
- Misses       21601    29335    +7734     
Flag Coverage Δ
inputsystem_MacOS_6000.0 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_MacOS_6000.0_project 77.34% <100.00%> (+0.04%) ⬆️
inputsystem_MacOS_6000.3 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_MacOS_6000.3_project 77.34% <100.00%> (+0.06%) ⬆️
inputsystem_MacOS_6000.4 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_MacOS_6000.4_project 77.35% <100.00%> (+0.06%) ⬆️
inputsystem_MacOS_6000.5 5.32% <0.00%> (+0.01%) ⬆️
inputsystem_MacOS_6000.5_project 77.38% <100.00%> (+0.06%) ⬆️
inputsystem_MacOS_6000.6 5.32% <0.00%> (+0.01%) ⬆️
inputsystem_MacOS_6000.6_project 77.38% <100.00%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.0 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.0_project 77.25% <100.00%> (+0.04%) ⬆️
inputsystem_Ubuntu_6000.3 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.3_project 77.24% <100.00%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.4 5.34% <0.00%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.4_project 77.25% <100.00%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.5 5.32% <0.00%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.5_project 77.29% <100.00%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.6 5.32% <0.00%> (+0.01%) ⬆️
inputsystem_Ubuntu_6000.6_project 77.29% <100.00%> (+0.07%) ⬆️
inputsystem_Windows_6000.0 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_Windows_6000.0_project 77.46% <100.00%> (+0.03%) ⬆️
inputsystem_Windows_6000.3 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_Windows_6000.3_project 77.46% <100.00%> (+0.06%) ⬆️
inputsystem_Windows_6000.4 5.33% <0.00%> (+0.01%) ⬆️
inputsystem_Windows_6000.4_project 77.47% <100.00%> (+0.06%) ⬆️
inputsystem_Windows_6000.5 5.32% <0.00%> (+0.01%) ⬆️
inputsystem_Windows_6000.5_project 77.51% <100.00%> (+0.06%) ⬆️
inputsystem_Windows_6000.6 5.32% <0.00%> (+0.01%) ⬆️
inputsystem_Windows_6000.6_project 77.51% <100.00%> (+0.06%) ⬆️

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 97.18% <100.00%> (+0.48%) ⬆️
.../Runtime/Plugins/InputForUI/InputSystemProvider.cs 87.64% <100.00%> (ø)

... and 215 files with indirect coverage changes

ℹ️ Need help interpreting these results?

@AswinRajGopal AswinRajGopal removed the request for review from Pauliusd01 February 17, 2026 11:43
@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? 👍/👎

Comment thread Assets/Tests/InputSystem/Plugins/InputForUITests.cs Outdated
Comment thread Assets/Tests/InputSystem/Plugins/InputForUITests.cs Outdated
@AswinRajGopal
Copy link
Copy Markdown
Collaborator Author

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

Hi @jfreire-unity could you please review this PR? or can you suggest another reviewers from the team to move it forward? it is been a while on my name. Thanks in advance :)

Copy link
Copy Markdown
Collaborator

@jfreire-unity jfreire-unity left a comment

Choose a reason for hiding this comment

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

As mentioned in Slack, have a look at the U-PR suggestions to see if they make any sense. And feel free to look if we need to extend the added test to look into the action map that's being disabled.

@AswinRajGopal
Copy link
Copy Markdown
Collaborator Author

Currently working on U-PR comments,

@u-pr
Copy link
Copy Markdown
Contributor

u-pr Bot commented May 22, 2026

Persistent review updated to latest commit 0771421

@u-pr
Copy link
Copy Markdown
Contributor

u-pr Bot commented May 22, 2026

PR Code Suggestions ✨

No code suggestions found for the PR.

@AswinRajGopal AswinRajGopal requested a review from Pauliusd01 May 23, 2026 18:42
@ekcoh
Copy link
Copy Markdown
Collaborator

ekcoh commented May 26, 2026

@AswinRajGopal It seems unclear whether the third u-pr feedback comment has been resolved? It has been marked resolved without a comment, but seems referenced code has not changed (as it have for the other 3). I would suggest adding a comment on that u-pr comment why it's not valid or not addressed or whether is incorrect. Then I would update the u-pr review to get a new review round based on current commits.

@u-pr
Copy link
Copy Markdown
Contributor

u-pr Bot commented May 26, 2026

Persistent review updated to latest commit 0acc808

@Pauliusd01
Copy link
Copy Markdown
Collaborator

FYI I am only free from next week

…own). For project-wide actions the play-mode lifecycle owns the asset, so the provider enables the UI map on init but leaves it as-is when shutting down.
@u-pr
Copy link
Copy Markdown
Contributor

u-pr Bot commented May 28, 2026

Persistent review updated to latest commit 2b5eadf

@u-pr
Copy link
Copy Markdown
Contributor

u-pr Bot commented May 28, 2026

Persistent review updated to latest commit 15e20a1

@AswinRajGopal AswinRajGopal requested a review from ekcoh May 28, 2026 15:20
@AswinRajGopal
Copy link
Copy Markdown
Collaborator Author

/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

This review identifies a critical state/event leak issue in the test suite where calling Initialize() twice on the same provider leads to duplicate global event subscriptions.

🤖 Helpful? 👍/👎

Comment thread Assets/Tests/InputSystem/Plugins/InputForUITests.cs Outdated
@AswinRajGopal
Copy link
Copy Markdown
Collaborator Author

/ci prv

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