-
Notifications
You must be signed in to change notification settings - Fork 326
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
Merged
ritamerkl
merged 35 commits into
develop
from
isxb-1482/fix-custom-processor-serializesbyIndex
Jul 2, 2025
Merged
Changes from 11 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
6504c53
Added test to cover the fix
AswinRajGopal e9cff62
Determine index from enum value and serialise accordingly for the asset.
AswinRajGopal 7284150
Fix test failure after fix, had to focus the dropdown field before ch…
AswinRajGopal 73890bd
Determine index from enum value and serialise accordingly for the asset.
AswinRajGopal 9020c5e
Merge branch 'isxb-1482/fix-custom-processor-serializesbyIndex' of ht…
AswinRajGopal 9819aab
Merge branch 'develop' into isxb-1482/fix-custom-processor-serializes…
AswinRajGopal 43278ad
Update CHANGELOG.md
AswinRajGopal a06e9d3
Merge branch 'develop' into isxb-1482/fix-custom-processor-serializes…
Pauliusd01 580e931
Address PR feedbacks, changelog changed, test name modified, comments…
AswinRajGopal 774190a
Address PR feedbacks, changelog changed, test name modified, comments…
AswinRajGopal 6d50a6b
Merge branch 'isxb-1482/fix-custom-processor-serializesbyIndex' of ht…
AswinRajGopal 7c7b927
Upgrade compatibility to fill the dropdown field with value
AswinRajGopal a521b32
Implement migrator for the old input action asset as we now serialize…
AswinRajGopal 8c65e40
Removed additional version constant and used the existing k_Version t…
AswinRajGopal 37d1dfb
Handle migration for LoadFromJson aswell and used NameAndParamerter p…
AswinRajGopal 8bc3ef0
Remove log statements and unused header.
AswinRajGopal 359f03d
Fix test failures and compiler errors.
AswinRajGopal b41abf8
Addressed PR comments, changed the migration logic a bit to deal with…
AswinRajGopal 8d168c8
Removed empty lines, reverted kVersion to private.
AswinRajGopal a81282c
Removed empty lines, reverted kVersion to private.
AswinRajGopal b3f63c9
Merge branch 'isxb-1482/fix-custom-processor-serializesbyIndex' of ht…
AswinRajGopal 40ce21e
Moved the optimization into migration function, assigned proper versi…
AswinRajGopal 261cbd6
Fix test failure checking an empty json, omitt versioning.
AswinRajGopal 42bb20c
Remove commented code and fix misplaced enums.
AswinRajGopal 8acf7fe
Merge branch 'develop' into isxb-1482/fix-custom-processor-serializes…
ekcoh 51994b7
Removed nullabe version fileds due to readability issues and boxing.
AswinRajGopal fbbacad
Patched the failing tests due the version introduction.
AswinRajGopal 101dd7c
Merge branch 'isxb-1482/fix-custom-processor-serializesbyIndex' of ht…
AswinRajGopal 1f6bd45
Revert "Patched the failing tests due the version introduction."
AswinRajGopal 42807fd
Fix failing tests by introducing versioning.
AswinRajGopal 34b0271
Merge branch 'develop' into isxb-1482/fix-custom-processor-serializes…
ekcoh a349aa5
Merge branch 'develop' into isxb-1482/fix-custom-processor-serializes…
ekcoh dc9452a
Merge branch 'develop' into isxb-1482/fix-custom-processor-serializes…
ritamerkl c38e483
Removing call to unity setup as wait for dirty for this test is not n…
AswinRajGopal d91a573
Merge branch 'develop' into isxb-1482/fix-custom-processor-serializes…
ritamerkl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
Assets/Tests/InputSystem.Editor/CustomProcessorEnumTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS | ||
|
||
using System; | ||
using NUnit.Framework; | ||
using System.Collections; | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
using UnityEngine.InputSystem; | ||
using UnityEngine.InputSystem.Editor; | ||
using UnityEngine.TestTools; | ||
using UnityEngine.UIElements; | ||
|
||
internal enum SomeEnum | ||
{ | ||
OptionA = 10, | ||
OptionB = 20 | ||
} | ||
|
||
#if UNITY_EDITOR | ||
[InitializeOnLoad] | ||
#endif | ||
internal class CustomProcessor : InputProcessor<float> | ||
{ | ||
public SomeEnum SomeEnum; | ||
|
||
#if UNITY_EDITOR | ||
static CustomProcessor() | ||
{ | ||
Initialize(); | ||
} | ||
#endif | ||
|
||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] | ||
private static void Initialize() | ||
{ | ||
InputSystem.RegisterProcessor<CustomProcessor>(); | ||
} | ||
|
||
public override float Process(float value, InputControl control) | ||
{ | ||
return value; | ||
} | ||
} | ||
|
||
internal class CustomProcessorEnumTest : UIToolkitBaseTestWindow<InputActionsEditorWindow> | ||
AswinRajGopal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
InputActionAsset m_Asset; | ||
|
||
public override void OneTimeSetUp() | ||
{ | ||
base.OneTimeSetUp(); | ||
m_Asset = AssetDatabaseUtils.CreateAsset<InputActionAsset>(); | ||
|
||
var actionMap = m_Asset.AddActionMap("Action Map"); | ||
|
||
actionMap.AddAction("Action", InputActionType.Value, processors: "Custom(SomeEnum=10)"); | ||
} | ||
|
||
public override void OneTimeTearDown() | ||
{ | ||
AssetDatabaseUtils.Restore(); | ||
base.OneTimeTearDown(); | ||
} | ||
|
||
public override IEnumerator UnitySetup() | ||
{ | ||
m_Window = InputActionsEditorWindow.OpenEditor(m_Asset); | ||
yield return base.UnitySetup(); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator ProcessorEnum_ShouldSerializeByValue_WhenSerializedToAsset() | ||
{ | ||
// Serialize current asset to JSON, and check that initial JSON contains default enum value for OptionA | ||
var json = m_Window.currentAssetInEditor.ToJson(); | ||
|
||
Assert.That(json.Contains("Custom(SomeEnum=10)"), Is.True, | ||
"Serialized JSON does not contain the expected custom processor string for OptionA."); | ||
|
||
// Query the dropdown with exactly two enum choices and check that the drop down is present in the UI | ||
var dropdownList = m_Window.rootVisualElement.Query<DropdownField>().Where(d => d.choices.Count == 2).ToList(); | ||
Assume.That(dropdownList.Count > 0, Is.True, "Enum parameter dropdown not found in the UI."); | ||
|
||
// Determine the new value to be set in the dropdown, focus the dropdown before dispatching the change | ||
AswinRajGopal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var dropdown = dropdownList.First(); | ||
var newValue = dropdown.choices[1]; | ||
dropdown.Focus(); | ||
dropdown.value = newValue; | ||
|
||
// Create and send a change event from OptionA to OptionB | ||
var changeEvent = ChangeEvent<Enum>.GetPooled(SomeEnum.OptionA, SomeEnum.OptionB); | ||
changeEvent.target = dropdown; | ||
dropdown.SendEvent(changeEvent); | ||
|
||
// Find the save button in the window, focus and click the save button to persist the changes | ||
var saveButton = m_Window.rootVisualElement.Q<Button>("save-asset-toolbar-button"); | ||
Assume.That(saveButton, Is.Not.Null, "Save Asset button not found in the UI."); | ||
saveButton.Focus(); | ||
SimulateClickOn(saveButton); | ||
|
||
Assert.That(dropdown.value, Is.EqualTo(newValue)); | ||
|
||
// Verify that the updated JSON contains the new enum value for OpitonB | ||
var updatedJson = m_Window.currentAssetInEditor.ToJson(); | ||
Assert.That(updatedJson.Contains("Custom(SomeEnum=20)"), Is.True, "Serialized JSON does not contain the updated custom processor string for OptionB."); | ||
|
||
yield return null; | ||
} | ||
} | ||
#endif | ||
|
2 changes: 2 additions & 0 deletions
2
Assets/Tests/InputSystem.Editor/CustomProcessorEnumTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.