Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Checking which controls scheme is currently active (New input system)

Discussion in 'Input System' started by Kamon145, Sep 12, 2023.

  1. Kamon145

    Kamon145

    Joined:
    Aug 27, 2022
    Posts:
    17
    Hello! I am working on my input system and I would like to change a variable based on which control scheme is currently being used. I am using the new input system and have two control schemes set up, "Gamepad" and "Mouse & Keyboard". I was using bits of code from the 3D unity starter assets but the way I have my input set up is slightly different and is causing me some issues. The code I am attempting to run is here :
    Code (CSharp):
    1. #if ENABLE_INPUT_SYSTEM
    2.     private PlayerInput _playerInput;
    3. #endif
    4.  
    5.     private bool IsCurrentDeviceMouse
    6.     {
    7.         get
    8.         {
    9. #if ENABLE_INPUT_SYSTEM
    10.  
    11.                 return _playerInput.currentControlScheme == "Mouse & Keyboard";
    12.  
    13. #else
    14.                 return false;
    15. #endif
    16.         }
    17.     }
    18.     private void CameraRotation()
    19.     {
    20.         // if there is an input and camera position is not fixed
    21.         if (_input.LookValue.sqrMagnitude >= _threshold && !LockCameraPosition)
    22.         {
    23.             //Don't multiply mouse input by Time.deltaTime;
    24.             float deltaTimeMultiplier = IsCurrentDeviceMouse ? 1.0f : Time.deltaTime;
    25.  
    26.             _cinemachineTargetYaw += _input.LookValue.x * deltaTimeMultiplier * Sensitivity;
    27.             _cinemachineTargetPitch += _input.LookValue.y * deltaTimeMultiplier * Sensitivity;
    28.  
    29.         }
    However, my player was not using the "Player Input" component before and adding it now causes loads of "MissingMethodException : Method 'InputReader.OnLook' not found (for context, the InputReader is the script that actually handles input from the player and passes it on to the player object, example :
    Code (CSharp):
    1.     public void OnLook(InputAction.CallbackContext context)
    2.     {
    3.         LookValue = context.ReadValue<Vector2>();
    4.     }
    )
    is there a way to check which control scheme is being used without the Player Input component? Or is that simply the best way to do it and I need to figure out how to make it work with my current setup?
     
  2. xiennastudio

    xiennastudio

    Joined:
    Aug 2, 2023
    Posts:
    19