-
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.
- Fixed an issue where `InputActionSetupExtensions.Remove` will result in `NullReferenceException` if the action being removed has no bindings. (ISXB-1688). | ||
- Fixed an issue where assigning a ``MonoBehaviour` field of type `InputActionReference` to an instance stored in `.inputactions` asset via `InputActionReference.Set` in playmode corrupts the originally referenced asset. (ISXB-1692). | ||
- Fixed an issue where `InputActionReference.Create(null)` returns `null` instead "of a reference object to the given action" as documented behaviour for the API. (ISXB-1693) | ||
- Fixed an issue where `InputActtionReference.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-1694) |
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.
Corrected spelling of 'InputActtionReference' to 'InputActionReference'."
- Fixed an issue where `InputActtionReference.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-1694) | |
- Fixed an issue where `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-1694) |
Copilot uses AI. Check for mistakes.
return $"{m_Asset.name}:{value.actionMap.name}/{value.name}"; | ||
return $"{m_Asset.name}:{m_ActionId}"; |
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.
Potential null reference exception if m_Asset
is null when value.actionMap
is not null. Should check m_Asset
before accessing m_Asset.name
.
return $"{m_Asset.name}:{value.actionMap.name}/{value.name}"; | |
return $"{m_Asset.name}:{m_ActionId}"; | |
return m_Asset != null ? $"{m_Asset.name}:{value.actionMap.name}/{value.name}" : $"{value.actionMap.name}/{value.name}"; | |
return m_Asset != null ? $"{m_Asset.name}:{m_ActionId}" : m_ActionId; |
Copilot uses AI. Check for mistakes.
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".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: