Search Unity

Input system doesn't work through PlayerInput

Discussion in 'Input System' started by kqmdjc8, Mar 16, 2021.

  1. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    102
    Hello. I am using new input system and can't get it working through a PlayerInput callback. I have in fact managed to get it working by using a generated C# script like InputMaster and then by subscribing to it
    Code (CSharp):
    1. controls.Player.Use.performed += context => UseActionPerformed();
    I can't get it working through the callbacks though. Any thoughts? Code + screenshots below:

    Code (CSharp):
    1. public class PlayerInputProvider : MonoBehaviour
    2. {
    3.     public void OnJump(InputAction.CallbackContext context)
    4.     {
    5.         Debug.Log("Player wants to jump!");
    6.     }
    7. }




    As you can see, I have tried both SendMessages() method and manual callbacks assigning. None succeed.
     
    Last edited: Mar 16, 2021
  2. Have you removed the CallbackContext parameter from your method definition? (Check the console for errors)

    Before:
    Code (CSharp):
    1. public void OnJump(InputAction.CallbackContext context)
    After:
    Code (CSharp):
    1. public void OnJump()
     
  3. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    102
    Yes, I have removed this line. It still does not work. I wonder if there is any kind of debugger to see if the new Input System doesn't recognize key presses or is it the problem with sending the message?
     
  4. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    102
    Yes, there is :D. InputSystem seems to recognize my key presses but the script isn't receiving any messages.
     
  5. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    102
    Okay. Figured out what was wrong. You actually have to add a device in your InputActions window. I thought it was there only to recognize like OnDeviceConnected OnDeviceDisconnected but seems that it required to put the device in a list in order to make it work.
     
    AlexDuff and Lurking-Ninja like this.
  6. AlexDuff

    AlexDuff

    Joined:
    Nov 9, 2020
    Posts:
    1
    This is it!!! thank god I was searching for this for a couple of days, can't believe I didn't see this anywhere! you are my savior