Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Custom Processor throwing error.

Discussion in 'Input System' started by SenseEater, Apr 25, 2020.

  1. SenseEater

    SenseEater

    Joined:
    Nov 28, 2014
    Posts:
    84
    I have simple Vector3 processor like this :
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. #if UNITY_EDITOR
    6. using UnityEditor;
    7. #endif
    8.  
    9. using UnityEngine.InputSystem;
    10.  
    11. #if UNITY_EDITOR
    12. [InitializeOnLoad]
    13. #endif
    14.  
    15. public class InputProcessorRotate : InputProcessor<Vector3>
    16. {
    17. #if UNITY_EDITOR
    18.     static InputProcessorRotate()
    19.     {
    20.         Initialize();
    21.     }
    22. #endif
    23.  
    24.     [RuntimeInitializeOnLoadMethod]
    25.     static void Initialize()
    26.     {
    27.         InputSystem.RegisterProcessor<InputProcessorRotate>();
    28.     }
    29.  
    30.     public Vector3 axis;
    31.     public float angle;
    32.  
    33.     public override Vector3 Process(Vector3 input, InputControl control)
    34.     {
    35.         var rotation = Quaternion.AngleAxis(angle, axis);
    36.         return rotation * input;
    37.     }
    38.  
    39.     //...
    40. }
    It read correctly in the processor list in Input Asset Window but on adding it to list , throws following exception
    Code (CSharp):
    1. ArgumentException: Don't know how to convert PrimitiveValue to 'Object'
    2. Parameter name: type
    3. UnityEngine.InputSystem.Utilities.PrimitiveValue.ConvertTo (System.TypeCode type) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.7/InputSystem/Utilities/PrimitiveValue.cs:227)
    4. UnityEngine.InputSystem.Utilities.NamedValue.ConvertTo (System.TypeCode type) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.7/InputSystem/Utilities/NamedValue.cs:28)
    5. 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-preview.7/InputSystem/Editor/AssetEditor/ParameterListView.cs:146)
    6. UnityEngine.InputSystem.Editor.Lists.NameAndParameterListView.OnAddElement (System.Object data) (at Library/PackageCache/com.unity.inputsystem@1.0.0-preview.7/InputSystem/Editor/AssetEditor/NameAndParameterListView.cs:96)
    7. UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, System.Int32 selected) (at <78f1ad0f25c84e3ca853e639f50d95f5>:0)
    8.  
     
    camposcreativestudios likes this.
  2. SenseEater

    SenseEater

    Joined:
    Nov 28, 2014
    Posts:
    84
    So i went through the built in processors and it seems there is no out of box support for drawing default serialized unity types.In my case Vector3 property is the issue.

    Would be great if we could have better auto handling of those properties for inspector in future.
     
    jwinn likes this.
  3. camposcreativestudios

    camposcreativestudios

    Joined:
    Jun 2, 2020
    Posts:
    2
    Did you find a solution to this? I'm having the same issue with a Vector2.
     
  4. SenseEater

    SenseEater

    Joined:
    Nov 28, 2014
    Posts:
    84
    Sort of. You can write custom inspector for your processor. as explained in the docs : https://docs.unity3d.com/Packages/c...ual/Processors.html#writing-custom-processors

    You need to do manually draw Vector2/Vector3 GUI field using relevant API. In your case you can use https://docs.unity3d.com/ScriptReference/EditorGUILayout.Vector2Field.html

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem.Editor;
    3. using UnityEditor;
    4.  
    5. public class InputProcessorRotateEditor : InputParameterEditor<InputProcessorRotate>
    6. {
    7.     public override void OnGUI()
    8.     {
    9.         var axis = new Vector3(target.x, target.y, target.z);
    10.         axis = EditorGUILayout.Vector3Field("Axis", axis);
    11.         target.x = axis.x;
    12.         target.y = axis.y;
    13.         target.z = axis.z;
    14.     }
    15. }
    16.  
     
    camposcreativestudios likes this.
  5. ttnet

    ttnet

    Joined:
    Jul 22, 2020
    Posts:
    2
    Hi, I tried your fix but doesn't do fix the issue for me. Did you change something in your processor code to make it work ? fields x, y ,z are not here on your first message. would you mind sharing the all code ?
     
  6. ExodusOTH

    ExodusOTH

    Joined:
    Nov 30, 2017
    Posts:
    44
    I have also just run into this problem. I do not have a solution yet.