Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Simple Custom Processor OnGUI not being called?

Discussion in 'Input System' started by SpookyCat, Jan 8, 2024.

  1. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,788
    Doing a simple PostProcessor to use a curve to modify a value. As the new Input System still can't display AnimationCurves without an error I did a simple Custom UI for it, but the OnGUI method is never called. Have I missed somethiong obvious?
    Processor Class: CurveProcessor.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. #if UNITY_EDITOR
    5. using UnityEditor;
    6. [InitializeOnLoad]
    7. #endif
    8. public class CurveProcessor : InputProcessor<float>
    9. {
    10.     [SerializeField]
    11.     AnimationCurve    curve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
    12.     public float test;
    13.  
    14. #if UNITY_EDITOR
    15.     static CurveProcessor()
    16.     {
    17.         Initialize();
    18.     }
    19. #endif
    20.  
    21.     [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    22.     static void Initialize()
    23.     {
    24.         InputSystem.RegisterProcessor<CurveProcessor>();
    25.     }
    26.  
    27.     public override float Process(float value, InputControl control)
    28.     {
    29.         return curve.Evaluate(value);
    30.     }
    31.  
    32.     public AnimationCurve GetCurve()
    33.     {
    34.         return curve;
    35.     }
    36. }
    37.  
    Editor Class: CurveProcessorEditor.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem.Editor;
    3. using UnityEditor;
    4.  
    5. public class CurveProcessorEditor :  InputParameterEditor<CurveProcessor>
    6. {
    7.     public override void OnGUI()
    8.     {
    9.         Debug.Log("OnGUI");
    10.         AnimationCurve curve = target.GetCurve();
    11.         curve = EditorGUILayout.CurveField("Curve", curve);
    12.         target.test = EditorGUILayout.Slider("Test", target.test, 0.0f, 1.0f);
    13.     }
    14. }
    15.  
    The code is doing something as it stops the default UI being displayed, but the Debug.Log message never appears in the console and there are no fields.
    Screenshot 2024-01-08 154016.png
     
  2. SpookyCat

    SpookyCat

    Joined:
    Jan 25, 2010
    Posts:
    3,788
    Are there any plans to allow non primitive types to be used in Processors without them throwing an error?