-
Notifications
You must be signed in to change notification settings - Fork 328
FIX: ISXB-1584, ISXB-1688, ISXB-1692, ISXB-1693, ISXB-1694, ISXB-1701 InputActionReference bug fixes and improved test coverage. #2248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
…been called and cached, then Set and then calling action again.
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. |
…onReference, simplification of InputActionImporter.
…g fixing of InputActionReference, added more tests.
…to support serialization within editor test. Added test utilities.
…echnologies/InputSystem into isxb-1584-input-action-reference
…ork since referencing editor types.
… InputActionReference unless there is a UI to configure it
…ained actions intact.
There was a problem hiding this 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(); | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionReference.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…Reference.cs Co-authored-by: Copilot <[email protected]>
…echnologies/InputSystem into isxb-1584-input-action-reference
@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. |
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. |
There was a problem hiding this 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.
-
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.
-
Does this mean that
InputActionReference.Set()
cannot be run at in Play-mode now? -
There's no guidance in the PR description to make the main bug work be fixed with this change. That could have been helpful.
-
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
This is the message I get when opening the ISXB-1584 project in 6.2.0f1 and using the package in this branch:
|
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); |
Description
Fixes the following issues:
InputActionReference.action
would return an incorrect (cached) action if set programmatically after the cached instance had been resolved.InputActionSetupExtensions.RemoveAction(action)
throws exception if attempting to remove an action that doesn't have any bindings.InputActionReference.Set
in playmode corrupts the referenced asset.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.InputActionReference.Set(null)
does not update the cached input action reference nor theScriptableObject.name
leading to incorrect action being returned and reference showing up as the path to the previously assigned action in Inspector.ISXB-1699 -This was a misinterpretation and have been reverted. Ticket marked "As Designed".InputActionAsset.RemoveActionMap
doesn't remove actions within the map, leaving them with stale references back to the map.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:
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 toInputActionReference
.InputActionReference
to eliminate name-shadowing warnings. Didn't touch public ones since a parameter rename would be unexpected after API publishing.InputActionReference
instances from assets withinInputActionImporter
.EditorPrefsTestUtils.cs
which is a test utility to simplify editor tests.CoreTests_Actions_References.cs
which extracts previous and newInputActionReference
play-mode tests into their own (partial) file.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:
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
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:
Changed
,Fixed
,Added
sections.Actions_CanResolveActionReferenceAndThenSetItToAnotherAction
During merge:
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.After merge: