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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bug Input not working (new input system)

Discussion in 'Input System' started by Liam_GameDev, Sep 10, 2023.

  1. Liam_GameDev

    Liam_GameDev

    Joined:
    Feb 5, 2023
    Posts:
    26
    I am having trouble getting the input to work for my run function. It has all the same setting and code as my jump Input and that works perfectly fine

    Code (CSharp):
    1. public void Run(InputAction.CallbackContext context)
    2.     {
    3.         if (context.performed)
    4.         {
    5.             isRunning = true;
    6.         }
    7.         else if (context.canceled)
    8.         {
    9.             isRunning = false;
    10.         }
    11.     }
     
  2. acasta

    acasta

    Joined:
    Feb 10, 2018
    Posts:
    8
    I'd suggest debugging your code and see where the problem is to provide a bit more info.
    Do you know how to use the debugger? If not, no worries. Something like this will help point out where something is going wrong.

    Code (CSharp):
    1. public void Run(InputAction.CallbackContext context)
    2. {
    3.     print("Button did something");
    4.     if (context.performed)
    5.     {
    6.         print("Button pressed");
    7.         isRunning = true;
    8.     }
    9.     else if (context.canceled)
    10.     {
    11.         print("Button press finished");
    12.         isRunning = false;
    13.     }
    14.     print("value: "+ isRunning);
    15. }
    Check the console and press your button to see what is happening.
     
  3. Liam_GameDev

    Liam_GameDev

    Joined:
    Feb 5, 2023
    Posts:
    26
    I already have, my result is that nothing happens when the key is pressed.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,003
    Which method of the Input System are you using to call this method? Methods don't just call themselves.

    You need to make sure it's properly wired up, such as subscribing this method to your Input Actions Map asset or your generated C# input actions.
     
  5. Liam_GameDev

    Liam_GameDev

    Joined:
    Feb 5, 2023
    Posts:
    26
    I'm using a player input and the Input is connected to an action map and is included in my generated script