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

Composite Binding Does Not Appear in Editor

Discussion in 'Input System' started by CashewTheCat, Nov 23, 2020.

  1. CashewTheCat

    CashewTheCat

    Joined:
    Nov 29, 2017
    Posts:
    17
    Hi,

    I've made two custom composite bindings. One of them works properly, but the other does not appear in the editor when mapping an Action. After stripping it down to bare bones, it seems that if I declare the class with `Vector2` as the generic type parameter, it does not appear. Changing it to `float` and updating ReadValue makes it work.

    Binding causing problems:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.     [InitializeOnLoad]
    3. #endif
    4.     [DisplayStringFormat("{firstPart}+{secondPart}")]
    5.     public class Vector2WithModifierComposite : InputBindingComposite<Vector2>
    6.     {
    7.         [InputControl(layout = "button")]
    8.         public int Modifier;
    9.         [InputControl(layout = "axis")]
    10.         public int Vector;
    11.         public override Vector2 ReadValue(ref InputBindingCompositeContext context)
    12.         {
    13.             return Vector2.zero;
    14.             //if (context.ReadValue<bool>(Modifier))
    15.             //    return context.ReadValue<Vector2, Vector2MagnitudeComparer>(Vector);
    16.             //return Vector2.zero;
    17.         }
    18.     }

    Working binding:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.     [InitializeOnLoad]
    3. #endif
    4.     [DisplayStringFormat("{firstPart}+{secondPart}")]
    5.     public class AxisWithModifierComposite : InputBindingComposite<float>
    6.     {
    7.         [InputControl(layout = "button")]
    8.         public int Modifier;
    9.         [InputControl(layout = "axis")]
    10.         public int Axis;
    11.  
    12.         public override float ReadValue(ref InputBindingCompositeContext context)
    13.         {
    14.             if (context.ReadValue<bool>(Modifier))
    15.                 return context.ReadValue<float>(Axis);
    16.             return 0;
    17.         }
    18.     }
    and registration:
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.     [InitializeOnLoad]
    3. #endif
    4.     public class InputBindingRegistration
    5.     {
    6.         static InputBindingRegistration()
    7.         {
    8.             InputSystem.RegisterBindingComposite<Vector2WithModifierComposite>();
    9.             InputSystem.RegisterBindingComposite<AxisWithModifierComposite>();
    10.             Debug.Log("Bindings registered");
    11.         }
    12.         //ensures the static constructor is called on time
    13.         [RuntimeInitializeOnLoadMethod]
    14.         static void Init() { }
    15.     }
     
  2. CashewTheCat

    CashewTheCat

    Joined:
    Nov 29, 2017
    Posts:
    17
    Well, I had the Action set to button, so I couldn't see it. Rubber duck debugging at its finest. (Can't figure out how to delete this post)