I’m trying to write a custom processor to smooth out vector input similar to what the old GetAxis system does. I am able to create and register the processor, but when I go to assign it in the asset editor, an argument exception is thrown:
ArgumentException: Don't know how to convert PrimitiveValue to 'Object'
Parameter name: type
UnityEngine.InputSystem.Utilities.PrimitiveValue.ConvertTo (System.TypeCode type) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Utilities/PrimitiveValue.cs:227)
UnityEngine.InputSystem.Utilities.NamedValue.ConvertTo (System.TypeCode type) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Utilities/NamedValue.cs:28)
UnityEngine.InputSystem.Editor.Lists.ParameterListView.Initialize (System.Type registeredType, UnityEngine.InputSystem.Utilities.ReadOnlyArray`1[TValue] existingParameters) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/ParameterListView.cs:146)
UnityEngine.InputSystem.Editor.Lists.NameAndParameterListView.OnAddElement (System.Object data) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Editor/AssetEditor/NameAndParameterListView.cs:96)
UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at <a20a50bbfaff4193bf6ba6b262f9a71f>:0)
My code for the processor is:
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEditor;
#if UNITY_EDITOR
[InitializeOnLoad]
#endif
public class SmoothMoveProcessor : InputProcessor<Vector2>
{
#if UNITY_EDITOR
static SmoothMoveProcessor()
{
Initialize();
}
#endif
[RuntimeInitializeOnLoadMethod]
static void Initialize()
{
InputSystem.RegisterProcessor<SmoothMoveProcessor>();
}
public float smoothRate = .5f;
public Vector2 previousValue = Vector2.zero;
public override Vector2 Process(Vector2 value, InputControl control)
{
float smoothedX = Mathf.Clamp(Mathf.Lerp(previousValue.x, value.x, smoothRate), -1, 1);
float smoothedY = Mathf.Clamp(Mathf.Lerp(previousValue.y, value.y, smoothRate), -1, 1);
Vector2 newValue = new Vector2(smoothedX, smoothedY);
previousValue = newValue;
return value;
}
}
I don’t know where the error could be. Besides the Input Asset, there are no other scripts as this is a test project. All help is appreciated.