Search Unity

Question New input system, how to get current control scheme?

Discussion in 'Input System' started by KeyGameUniverse, Jul 18, 2020.

  1. KeyGameUniverse

    KeyGameUniverse

    Joined:
    Jul 18, 2013
    Posts:
    39
    I have searched a lot but i cannot find how to check what control scheme i am using.

    For example i have a variable that i need it to be different for keyboard & mouse from gamepad.

    Is there any way to know that my last input was from gamepad?
     
  2. I assume you use the Actions. If you do that, through the CallbackContext you can ask for the current control:
    https://docs.unity3d.com/Packages/c...putSystem_InputAction_CallbackContext_control

    The control is an InputControl which has a path property. It tells you what is the control was used to trigger the action (for example wKey or something). You can use this path or you can walk back through the parent properties to the root InputControl which is the InputDevice itself.
     
    RunninglVlan likes this.
  3. KeyGameUniverse

    KeyGameUniverse

    Joined:
    Jul 18, 2013
    Posts:
    39
    For example i have
    Code (CSharp):
    1.     void Awake()
    2.     {
    3.         controls = new PlayerInputSystem();
    4.         controls.RadialUI.Position.performed += mr_ctx => MousePos(mr_ctx.ReadValue<Vector2>(), mr_ctx);
    5.         RadialMenuInitialize();
    6.     }
    and when i use
    Code (CSharp):
    1.  public void MousePos(Vector2 mousePos, InputAction.CallbackContext context)
    2.     {
    3.             mousePosition = mousePos;
    4.     }
    i get what i need for the keyboard and mouse. My radial menu highlights what item i need.Now when i switch to gamepad the vector2 position is moving so slow and i cannot highlight my radial menu item.

    The only solution i could use was increasing mousePosition = mousePos * 2000 and it works for gamepad but doesn't work for keyboard and mouse.

    So if could read what control scheme is , i can use mousePosition = mousePos; for keyboard&mouse and mousePosition = mousePos * 2000 for gamepad.

    Thank you for all your help.
     
  4. RunninglVlan

    RunninglVlan

    Joined:
    Nov 6, 2018
    Posts:
    182
    Well, have you tried InputAction.CallbackContext that Lurking-Ninja suggested?
     
  5. Fridgecrisis

    Fridgecrisis

    Joined:
    Apr 1, 2017
    Posts:
    3
    Fep310 likes this.
  6. MineCode27

    MineCode27

    Joined:
    Dec 27, 2013
    Posts:
    9
    I see you are trying ot solve your problem with different deltas form mouse and gampad input in your code. I would suggest you that you use processors (scale vector 2) on your action for gamepad
     
  7. unity_TzpyWNDSHXpr_A

    unity_TzpyWNDSHXpr_A

    Joined:
    Jul 5, 2021
    Posts:
    1
    very usefull thx