Skip to content

Conversation

ekcoh
Copy link
Collaborator

@ekcoh ekcoh commented Sep 29, 2025

Description

Fixes the following issues:

  • https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1584, where InputActionReference.action would return an incorrect (cached) action if set programmatically after the cached instance had been resolved.
  • ISXB-1688 - InputActionSetupExtensions.RemoveAction(action) throws exception if attempting to remove an action that doesn't have any bindings.
  • ISXB-1692 - Assigning an InputActionReference field stored in an .inputactions asset via InputActionReference.Set in playmode corrupts the referenced asset.
  • ISXB-1693 - InputActionReference.Create(null) returns null instead "of a reference object to the given action". If its desirable to assign a reference to null when action is null, one should not call Create to begin with.
  • ISXB-1694 - InputActionReference.Set(null) does not update the cached input action reference nor the ScriptableObject.name leading to incorrect action being returned and reference showing up as the path to the previously assigned action in Inspector.
  • ISXB-1699 - InputActionAsset.RemoveActionMap doesn't remove actions within the map, leaving them with stale references back to the map. This was a misinterpretation and have been reverted. Ticket marked "As Designed".
  • ISXB-1701 - Inspector field of type InputActionReference isn't reflecting broken reference in case action is deleted from asset, action map is deleted from asset or the asset itself is deleted.

Revisiting/altering fixes of the previous tickets:

The above revisited tickets reference the problem of InputActionReference run-time objects not being reset when exiting play-mode with domain reloads disabled. To get this scenario covered, this scenario is now included in the added editor tests. Tested both with and without domain reloads enabled.

Additional changes made:

  • Simplified code in InputSystemProvider.cs (UITK integration) since there is no reason to use InputActionReference in that class as long as there is no UI to edit it implemented. If such a UI is added later it can easily be converted back to InputActionReference.
  • Renamed function arguments in non-public functions of InputActionReference to eliminate name-shadowing warnings. Didn't touch public ones since a parameter rename would be unexpected after API publishing.
  • Simplified loading code of InputActionReference instances from assets within InputActionImporter.
  • Adds EditorPrefsTestUtils.cs which is a test utility to simplify editor tests.
  • Adds CoreTests_Actions_References.cs which extracts previous and new InputActionReference play-mode tests into their own (partial) file.
  • Adds DumpInputActionReferences.cs which extends "QA Tools" with ability to dump a list of all input action references (loaded + assets) into the console via QA Tools Unity menu.

Open issues/questions to reviewers:

  • Property drawer for input action references is currently conditionally compiled depending on project-wide input actions. This makes little sense now, but if the check is removed we get a dependency on search context that isn't available in that version, so we might want to land this post 2021.3 EoL or add a similar fix for 2021.3? (Currently missing on PR)

Testing status & QA

Added a bunch of functional tests that replicates the problematic scenarios mentioned above. Both play-mode functional tests as well as edit-mode as well as transitional editor-mode to play-mode and play-mode to edit-mode editor tests were added.

Removed some code related to project-wide-actions in property drawer I believe @jfreire-unity added. I do not think it is needed as a special case anymore and I also think it was incorrect to change the users objects.

Altered a previous play-mode fix by @timkeo but it is essentially intact to previous behavior. I think there is opportunity to change this later to only use Object.FindObjectsByType(true) instead of Resources.FindObjectsByType() as an optimisation after this has landed?

Haven''t tested on 2021.3 which might be behaving differently but I do not know if we should bother since it is soon EoL.

Overall Product Risks

  • Complexity: Medium
  • Halo Effect: Large

InputActionReferences are used all over the place so this is a serious bug that can have impact, especially on more complex projects.

Comments to reviewers

Recommend double checking the repro project with this fix.

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 added: Actions_CanResolveActionReferenceAndThenSetItToAnotherAction
    • Performance tests. - None
    • Integration tests. - None
  • 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.

…been called and cached, then Set and then calling action again.
@ekcoh ekcoh requested review from K-Tone and Pauliusd01 September 29, 2025 20:03
@codecov-github-com
Copy link

codecov-github-com bot commented Sep 29, 2025

Codecov Report

Attention: Patch coverage is 89.17197% with 51 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
Assets/Tests/InputSystem.Editor/TestUtils.cs 17.07% 34 Missing ⚠️
...System/Editor/AssetImporter/InputActionImporter.cs 81.48% 5 Missing ⚠️
...pertyDrawers/InputActionReferencePropertyDrawer.cs 73.33% 4 Missing ⚠️
...s/Tests/InputSystem.Editor/EditorPrefsTestUtils.cs 85.71% 3 Missing ⚠️
...system/InputSystem/Actions/InputActionReference.cs 93.33% 3 Missing ⚠️
...utSystem.Editor/InputActionReferenceEditorTests.cs 97.61% 2 Missing ⚠️
@@             Coverage Diff             @@
##           develop    #2248      +/-   ##
===========================================
+ Coverage    76.70%   76.87%   +0.17%     
===========================================
  Files          465      469       +4     
  Lines        87919    88282     +363     
===========================================
+ Hits         67442    67871     +429     
+ Misses       20477    20411      -66     
Flag Coverage Δ
inputsystem_MacOS_2021.3 5.94% <22.05%> (+0.02%) ⬆️
inputsystem_MacOS_2022.3 5.40% <16.85%> (+0.02%) ⬆️
inputsystem_MacOS_2022.3_project 74.76% <88.43%> (+0.18%) ⬆️
inputsystem_MacOS_6000.0 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.0_project 76.67% <88.95%> (+0.16%) ⬆️
inputsystem_MacOS_6000.2 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.2_project 76.66% <88.95%> (+0.16%) ⬆️
inputsystem_MacOS_6000.3 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.3_project 76.66% <88.95%> (+0.16%) ⬆️
inputsystem_MacOS_6000.4 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_MacOS_6000.4_project 76.66% <88.95%> (+0.16%) ⬆️
inputsystem_Ubuntu_2021.3 5.94% <22.05%> (+0.02%) ⬆️
inputsystem_Ubuntu_2022.3 5.40% <16.85%> (+0.02%) ⬆️
inputsystem_Ubuntu_2022.3_project 74.56% <88.43%> (+0.16%) ⬆️
inputsystem_Ubuntu_6000.0 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.0_project 76.47% <88.95%> (+0.15%) ⬆️
inputsystem_Ubuntu_6000.2 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.2_project 76.47% <88.95%> (+0.15%) ⬆️
inputsystem_Ubuntu_6000.3 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.3_project 76.47% <88.95%> (+0.15%) ⬆️
inputsystem_Ubuntu_6000.4 5.19% <0.00%> (-0.01%) ⬇️
inputsystem_Ubuntu_6000.4_project 76.47% <88.95%> (+0.15%) ⬆️
inputsystem_Windows_2021.3 5.94% <22.05%> (+0.02%) ⬆️
inputsystem_Windows_2022.3 5.40% <16.85%> (+0.02%) ⬆️
inputsystem_Windows_2022.3_project 74.89% <88.43%> (+0.16%) ⬆️
inputsystem_Windows_6000.0 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.0_project 76.79% <88.95%> (+0.14%) ⬆️
inputsystem_Windows_6000.2 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.2_project 76.79% <88.95%> (+0.14%) ⬆️
inputsystem_Windows_6000.3 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.3_project 76.79% <88.95%> (+0.14%) ⬆️
inputsystem_Windows_6000.4 5.18% <0.00%> (-0.01%) ⬇️
inputsystem_Windows_6000.4_project 76.79% <88.95%> (+0.14%) ⬆️

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

Files with missing lines Coverage Δ
...r/InputActionReferencePropertyDrawerEditorTests.cs 100.00% <100.00%> (ø)
Assets/Tests/InputSystem/CoreTests_Actions.cs 97.77% <100.00%> (-0.01%) ⬇️
...s/Tests/InputSystem/CoreTests_Actions_Reference.cs 100.00% <100.00%> (ø)
.../InputSystem/Actions/InputActionSetupExtensions.cs 79.09% <100.00%> (ø)
...s/com.unity.inputsystem/InputSystem/InputSystem.cs 83.44% <100.00%> (+0.39%) ⬆️
...utSystem/Plugins/InputForUI/InputSystemProvider.cs 86.60% <100.00%> (-0.37%) ⬇️
...utSystem.Editor/InputActionReferenceEditorTests.cs 97.61% <97.61%> (ø)
...s/Tests/InputSystem.Editor/EditorPrefsTestUtils.cs 85.71% <85.71%> (ø)
...system/InputSystem/Actions/InputActionReference.cs 90.10% <93.33%> (+30.85%) ⬆️
...pertyDrawers/InputActionReferencePropertyDrawer.cs 65.00% <73.33%> (+65.00%) ⬆️
... and 2 more

... and 11 files with indirect coverage changes

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

@ekcoh
Copy link
Collaborator Author

ekcoh commented Sep 29, 2025

This solves the incorrect return value, but it seems it is not enough to solve the reported problem so moving this back to draft mode for more work.

@ekcoh ekcoh changed the title FIX: ISXB-1584 InputActionReference.action returns the incorrect action if set programmatically. FIX: ISXB-1584, ISXB-1690 InputActionReference bug fixes and improved test coverage. Sep 30, 2025
@ekcoh ekcoh changed the title FIX: ISXB-1584, ISXB-1690 InputActionReference bug fixes and improved test coverage. FIX: ISXB-1584, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1699, ISXB-1701 InputActionReference bug fixes and improved test coverage. Oct 3, 2025
@ekcoh ekcoh changed the title FIX: ISXB-1584, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1699, ISXB-1701 InputActionReference bug fixes and improved test coverage. FIX: ISXB-1593, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1699, ISXB-1701 InputActionReference bug fixes and improved test coverage. Oct 3, 2025
@ekcoh ekcoh changed the title FIX: ISXB-1593, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1699, ISXB-1701 InputActionReference bug fixes and improved test coverage. FIX: ISXB-1584, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1699, ISXB-1701 InputActionReference bug fixes and improved test coverage. Oct 3, 2025
@ekcoh ekcoh changed the title FIX: ISXB-1584, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1699, ISXB-1701 InputActionReference bug fixes and improved test coverage. FIX: ISXB-1584, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1701 InputActionReference bug fixes and improved test coverage. Oct 6, 2025
Copy link
Collaborator

@timkeo timkeo left a comment

Choose a reason for hiding this comment

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

Reviewed the change to my bug fix and skimmed though some of the other changes.

{
DumpReferences();
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be part of our Input Debugger interface instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe, right now I just put it into our QA asset scripts since I did it to investigate bugs and felt it had more value to keep than removing it, but maybe someone would be interested in it. I would say there is no obvious user-value in it, but maybe for ourselves. However, you likely want snapshots and this was simple and sufficient to solve such problems. I do not intend to move it there as part of this PR at least.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

However its handy to be able to see which InputActionReferences exist in memory and on disc as serialised SOs

@Pauliusd01
Copy link
Collaborator

Seeing some new warnings that don't show up in develop:

image

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 8, 2025

Seeing some new warnings that don't show up in develop:

image

Good catch, I implemented it with 2023.3 so should check newer which I assume this is.

@jfreire-unity
Copy link
Collaborator

Seeing some new warnings that don't show up in develop:

image

Yes, also saw this, so I will wait until it's fixed before approving.

@jfreire-unity jfreire-unity requested a review from Copilot October 9, 2025 14:57
Copy link
Contributor

@Copilot 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 multiple bugs related to InputActionReference handling and improves test coverage. The main purpose is to resolve issues where InputActionReference would return incorrect cached actions, fail to handle null bindings properly, and not properly reflect broken references in the Inspector.

Key changes include:

  • Enhanced InputActionReference validation and caching logic to prevent stale references
  • Fixed null pointer exceptions when removing actions without bindings
  • Added immutability checks to prevent corruption of asset-backed references
  • Improved property drawer behavior for broken references

Reviewed Changes

Copilot reviewed 17 out of 26 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
InputActionReference.cs Core fixes for reference validation, caching, and immutability checks
InputActionSetupExtensions.cs Fixed null reference exception when removing actions without bindings
InputSystemProvider.cs Simplified to use direct InputAction references instead of InputActionReference wrappers
InputActionReferencePropertyDrawer.cs Enhanced property drawer to handle broken references by showing "None" instead of stale data
InputActionImporter.cs Added automatic invalidation of references when assets are imported/deleted
InputSystem.cs Updated method name from ResetCachedAction to InvalidateAll
CHANGELOG.md Added documentation for all fixed issues
Test files Added comprehensive test coverage for reference behavior and edge cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 9, 2025

@jfreire-unity @Pauliusd01 I think I have eliminated the warnings on this branch now. The two key warnings must be present on develop and should be fixed separately. While fixing I realised the associated code could be simplified.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 10, 2025

I guess we should investigate if we can have an automated test that could fail if any warning is generated that maps to our assemblies.

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

Sorry to take so long to review.

  1. I'm not able to fix the main issue (ISXB-1584) as it now raises an error. I also don't understand what should I do based on the exception logged message.

  2. Does this mean that InputActionReference.Set() cannot be run at in Play-mode now?

  3. There's no guidance in the PR description to make the main bug work be fixed with this change. That could have been helpful.

  4. I'm much longer to review because there are a lot of things we're fixing in this PR and I'm not familiar with the impact of all the changes.

The only think I have to point out is that to me is that the changes raising an error for ISXB-1584 are a relatively impactfull breaking change, unless I'm seeing this wrong.
If I'm indeed correct, then let's just make this a bit more explicit and add maybe one example in a Discussions post or something. Happy to chat about it.


public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
OnGUI(position, property, label);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason to factor out the code to call a single function in this override?

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 is just to allow some kind of testability of the property drawer, its not ideal but I couldn't come up with anything better unless you have ideas?

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 see no way to mock the ObjectField otherwise

/// <summary>
/// Utility to simplify editor tests with respect to editor preferences.
/// </summary>
internal static class EditorPrefsTestUtils
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

// If we cannot get the path of our reference, we cannot be a persisted asset within an InputActionAsset.
var path = UnityEditor.AssetDatabase.GetAssetPath(reference);
if (path == null)
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems reasonable to have code coverage of this case? See all the 3 codecov warnings in this file (not sure if they are false positives as well).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for calling this out, will check to make sure its tested with a reference not in an asset

m_Asset = asset;
m_ActionId = action.id.ToString();
name = GetDisplayName(action);
CheckImmutableReference();
Copy link
Collaborator

@jfreire-unity jfreire-unity Oct 10, 2025

Choose a reason for hiding this comment

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

Are we now considering InputActionReference immutables during runtime (PlayMode/Standalone) and so Set can't be used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Set can be used if the reference is not an asset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we allow Set on asset we mutate our sub-asset references inside .inputactions which is a huge problem since the operation will be persistent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hence

reference = InputActionReference.Create(something);
reference.Set(somethingElse);

is completely fine

@jfreire-unity
Copy link
Collaborator

jfreire-unity commented Oct 10, 2025

This is the message I get when opening the ISXB-1584 project in 6.2.0f1 and using the package in this branch:

InvalidOperationException: Attempting to mutate an immutable InputActionReference instance. This is not allowed since it would modify the source asset.Instead use InputActionReference.Create(action) to create a new in-memory instance or serialize it as a separate asset if it survive domain reloads.

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 10, 2025

This is the message I get when opening the ISXB-1584 project in 6.2.0f1 and using the package in this branch:

InvalidOperationException: Attempting to mutate an immutable InputActionReference instance. This is not allowed since it would modify the source asset.Instead use InputActionReference.Create(action) to create a new in-memory instance or serialize it as a separate asset if it survive domain reloads.

Could you elaborate a bit more on the reproduction steps? Just opening the repo root without doing anything?

@jfreire-unity
Copy link
Collaborator

This is the message I get when opening the ISXB-1584 project in 6.2.0f1 and using the package in this branch:

InvalidOperationException: Attempting to mutate an immutable InputActionReference instance. This is not allowed since it would modify the source asset.Instead use InputActionReference.Create(action) to create a new in-memory instance or serialize it as a separate asset if it survive domain reloads.

Could you elaborate a bit more on the reproduction steps? Just opening the repo root without doing anything?

I downloaded the "bug project", used this PR branch, and got that error when entering playmode. I'll test a 3rd time now from scratch

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 10, 2025

This is the message I get when opening the ISXB-1584 project in 6.2.0f1 and using the package in this branch:

InvalidOperationException: Attempting to mutate an immutable InputActionReference instance. This is not allowed since it would modify the source asset.Instead use InputActionReference.Create(action) to create a new in-memory instance or serialize it as a separate asset if it survive domain reloads.

Could you elaborate a bit more on the reproduction steps? Just opening the repo root without doing anything?

I downloaded the "bug project", used this PR branch, and got that error when entering playmode. I'll test a 3rd time now from scratch

I now I understand, sorry, Friday-slowness, yes, the repro scenario cannot be allowed. It corrupts the assets. Try the original one if you are curious and see that after exiting playmode, asset A is containing a reference to a sub-asset in asset B......

@ekcoh
Copy link
Collaborator Author

ekcoh commented Oct 10, 2025

This is the message I get when opening the ISXB-1584 project in 6.2.0f1 and using the package in this branch:

InvalidOperationException: Attempting to mutate an immutable InputActionReference instance. This is not allowed since it would modify the source asset.Instead use InputActionReference.Create(action) to create a new in-memory instance or serialize it as a separate asset if it survive domain reloads.

Could you elaborate a bit more on the reproduction steps? Just opening the repo root without doing anything?

I downloaded the "bug project", used this PR branch, and got that error when entering playmode. I'll test a 3rd time now from scratch

I now I understand, sorry, Friday-slowness, yes, the repro scenario cannot be allowed. It corrupts the assets. Try the original one if you are curious and see that after exiting playmode, asset A is containing a reference to a sub-asset in asset B......

I haven't replied to user yet, but the recommendation will be to instead.

reference = InputActionReference.Create(desiredAction);

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.

5 participants