Search Unity

Check where input is coming from

Discussion in 'Input System' started by Reddevildragg, Oct 9, 2019.

  1. Reddevildragg

    Reddevildragg

    Joined:
    May 19, 2014
    Posts:
    50
    With the new input system is there a way to check what control scheme an input is coming from, or to disable a particular input.

    What i need to do is movement with WASD to work only when the right mouse is held down. But if this movement is being processed from a controler axis to just ignore the right click requirement.

    Happy for it to be that if a controller plugged in then the keyboard/mouse is disabled and assuming i can do something around the control schemes to do this, but not 100% sure what the process of this would be

    Thanks
     
  2. Reddevildragg

    Reddevildragg

    Joined:
    May 19, 2014
    Posts:
    50
    figured it out, if anyone else stumbles across the need for this i made a vector2withmod custom composite

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. [InitializeOnLoad] // Automatically register in editor.
    3. #endif
    4. public class Vector2CompositeWithModifierComposite : Vector2Composite
    5. {
    6.      [InputControl(layout = "Button")] public int modifier;
    7.    
    8.      // This method computes the resulting input value of the composite based
    9.      // on the input from its part bindings.
    10.      public override Vector2 ReadValue(ref InputBindingCompositeContext context)
    11.      {
    12.          return context.ReadValueAsButton(modifier) ? base.ReadValue(ref context) : default;
    13.      }
    14.    
    15.      static Vector2CompositeWithModifierComposite()
    16.      {
    17.          InputSystem.RegisterBindingComposite<Vector2CompositeWithModifierComposite>();
    18.      }
    19.      [RuntimeInitializeOnLoadMethod]
    20.      static void Init() {} // Trigger static constructor.
    21. }
     
  3. Jichaels

    Jichaels

    Joined:
    Dec 27, 2018
    Posts:
    237
    You can access the current control scheme using InputPlayer.currentControlScheme (or just controlScheme on older versions).