-
Notifications
You must be signed in to change notification settings - Fork 321
FIX: Custom processors serialises enum by index rather than by value. #2164
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?
FIX: Custom processors serialises enum by index rather than by value. #2164
Conversation
…anging the value.
…tps://github.com/Unity-Technologies/InputSystem into isxb-1482/fix-custom-processor-serializesbyIndex
@AswinRajGopal Its generally recommended to add one developer on the team and one QA as reviewers on the PR when published. This will help making sure you receive feedback on it. Looks like there are CI failures for non-required tests and that branch is outdated. I would recommend updating the branch (which will automatically re-run CI). |
@AswinRajGopal I notice you have published internal URLs in this public-facing PR. This should be avoided. Instead use public URLs to issue tickets when available and otherwise only use issue number (without link). I will remove the URLs for now. |
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 looking into this @AswinRajGopal! Left some comments on things to address.
… added, made classes and enums internal and refactor.
… added, made classes and enums internal and refactor.
…tps://github.com/Unity-Technologies/InputSystem into isxb-1482/fix-custom-processor-serializesbyIndex
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 addressing comments. Changes look good to me now.
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.
One concern I noticed is that the enum field is blank after upgrading to the new version, requiring the user to repick and save. Real problem? Any way to fix it?
Hi @Pauliusd01 could you please give me the steps to repro this issue? which version should I upgrade? Thanks. |
Your version. Steps are: Open the user project -> Upgrade the version to yours (package manager -> add from disk -> point to the version with your changes) -> observe the user's enum field is blank |
Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/ParameterListView.cs
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## develop #2164 +/- ##
===========================================
+ Coverage 65.45% 67.69% +2.23%
===========================================
Files 367 367
Lines 53505 53565 +60
===========================================
+ Hits 35024 36261 +1237
+ Misses 18481 17304 -1177
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 34 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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.
Changes look ok to me, added some suggestions to motivate complex code parts for increased readability. Would also recommend checking the codecov bot suggestions for logic not being tested.
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
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 think the PR as it is increases the tech debt in a way that is not worth the fix.
I believe there are better ways to achieve the desired outcome, and if not I would rather take the fix without the migration.
Take a look at migrating the data during importing, let me know if you have any questions
… the enums by value in the processors.
6bfc950
to
a521b32
Compare
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
…o handle migration.
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.
Marking this Request Changes based on code being in impropriate places given that this is handling the migration in-memory (See comments).
While this PR now handles multi-version parsing I struggle with two main issues:
- The parsing is inside the importer which is fine in one sense, but it implies this won't work (produce incorrect results), for a JSON loaded in a player via LoadFromJson directly.
- The migration code is heavily modifying strings which is unfortunate but maybe not possible to avoid since the processor definitions are actually strings to begin with. So as long as we mark dirty the user is likely not experiencing this much anyway if existing assets are migrated in edit-mode.
It might be that migrating directly in https://github.com/Unity-Technologies/InputSystem/blob/develop/Packages/com.unity.inputsystem/InputSystem/Actions/InputActionMap.cs#L1609 reduces the complexity since this is where an action is parsed. However doing this might require the version to be parsed first prior to parsing the asset to be able to reason about the version.
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetEditor/ParameterListView.cs
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs
Outdated
Show resolved
Hide resolved
…arser, moved the migration funciton to the InputActionAsset.
accd69f
to
8bc3ef0
Compare
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 updating. Some additional (hopefully final) batch of feedback.
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
Packages/com.unity.inputsystem/InputSystem/Actions/InputActionAsset.cs
Outdated
Show resolved
Hide resolved
… the parsed json.
…tps://github.com/Unity-Technologies/InputSystem into isxb-1482/fix-custom-processor-serializesbyIndex
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 a smaller now which I think is good and easier to read. I think the version used in comparison in a few places needs replacing but apart from that looks good to me. But it seems the assets needs updating to pass CI.
@@ -379,6 +398,11 @@ public void LoadFromJson(string json) | |||
throw new ArgumentNullException(nameof(json)); | |||
|
|||
var parsedJson = JsonUtility.FromJson<ReadFileJson>(json); | |||
if ((parsedJson.maps?.Length ?? 0) > 0 && (parsedJson.version ?? 0) < JsonVersion.Current) |
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.
JsonVersion.Current
here should probably be JsonVersion.Version1
since if we move on to version 2 later we do not need to do this migration step for version 1 json files?
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.
Additionally this may be skipped if the action:
- Do not contain actions
- Do not contain processors
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.
Minor: but you might as well move these "optimization" checks into the Migrate Json to remove the complexity from here and call it unconditionally, e.g. "MigrateJsonFromVersion0ToVersion1IfNeeded(ref parsedJson)"
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.
Yes we should skip migration in case the input action doesn't contain action and processors.
parsedJson.maps[mi] = mapJson; | ||
} | ||
// Bump the version so we never re-migrate | ||
parsedJson.version = JsonVersion.Current; |
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 should be assigned JsonVersion.Version1 right? Current might be Version 2 or higher in the future which would make this incorrect then
internal void MigrateJson(ref ReadFileJson parsedJson) | ||
{ | ||
var existing = parsedJson.version ?? JsonVersion.Version0; | ||
if (existing >= JsonVersion.Current) |
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 should compare to JsonVersion.Version1 instead of Current right?
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.
Yes right, my bad I mis aligned the enum values. I'll modify.
Description
Bug: https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1474
Port 1.13.1
The issue is that the DropdownField expects a selected index (starting at 0), but the enum’s underlying values (10, 20, 30..) don't match these indices. Instead of passing the enum’s integer value directly, I have mapped the value to the correct index in the list of enum options.
An automated test added which validates that a custom input processor with an enumerated parameter integrates correctly with both the Unity Input System’s asset serialization and its UI.
The issue is that
Testing status & QA
Verified manually in windows machine with the provided repro project.
Authored an automated test to cover the fix.
Observer details of the test run:
Overall Product Risks
Comments to reviewers
Checklist
Before review:
Changed
,Fixed
,Added
sections.Area_CanDoX
,Area_CanDoX_EvenIfYIsTheCase
,Area_WhenIDoX_AndYHappens_ThisIsTheResult
.During merge:
NEW: ___
.FIX: ___
.DOCS: ___
.CHANGE: ___
.RELEASE: 1.1.0-preview.3
.After merge: