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

What's the equivalent to Input.GetButton(name) and Input.GetAxis(name)?

Discussion in 'Input System' started by JUSTCAMH, Nov 13, 2019.

  1. JUSTCAMH

    JUSTCAMH

    Joined:
    Dec 8, 2018
    Posts:
    18
    I know that you can bind once off presses using actions, but how do I listen for input in my update loop? I want to know every frame that a specific control is being held. What's the best way to do comething like movement, wherein each frame of the button being held, the character is moved?
    What are the equivalents to Input.GetButton() and Input.GetAxis() in the Input System?

    This sounds like simple stuff, but I just can't find the documentation for it.
     
  2. JUSTCAMH

    JUSTCAMH

    Joined:
    Dec 8, 2018
    Posts:
    18
    Furthermore, is there any equivalent to Input.GetButtonDown() and Input.GetButtonUp() that could be used in update to make the new input system more usable?
     
    ostibilas likes this.
  3. JPhilipp

    JPhilipp

    Joined:
    Oct 7, 2014
    Posts:
    56
    Came here looking for the Input.GetAxis("Mouse Y") equivalent as well.
     
  4. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Some migration help can be found here in the docs.

    Code (CSharp):
    1. if (Mouse.current.leftButton.isPressed)
    2.    /* ... */;
    There is wasPressedThisFrame and wasReleasedThisFrame. In general, though, would recommend not using them and using actions instead as the current implementation of wasXXXThisFrame is simply based on comparing the current state to the state from the last frame -- which won't give the expected behavior for state changes within frames.

    Code (CSharp):
    1. Mouse.current.position.ReadValue().y
     
    makaka-org and JUSTCAMH like this.
  5. SuperLemonBits

    SuperLemonBits

    Joined:
    Feb 28, 2016
    Posts:
    7
    Continuing with this original question, is there something like:

    Code (CSharp):
    1. UnityEngine.InputSystem.PlayerInput playerInput = ...;
    2. bool jump = playerInput.GetActionDown("Jump");
    That would be just great
     
    JUSTCAMH likes this.
  6. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Code (CSharp):
    1. bool jump = playerInput.actions["jump"].triggered;
     
    JUSTCAMH likes this.
  7. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    880
    Is there a similar trick for touch holding on mobiles?
     
  8. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    187
    What about something like
    Code (CSharp):
    1. if(BitConverter.ToBoolean(Vive_RawByteArray,0) == true)
    2. {
    3. OnViveGripButtonDown.Invoke();
    4. }
    Basically wondering what the setup would be for getting the Native Array of bytes that the Input System uses. Using the debugger I can see the offsets and know where they are mapped, but dont yet know how to get that data.

    I see the above post but it requires you to put in "Jump". Looking for a way to create references and check them.
     
    Last edited: Apr 1, 2021
  9. SuperLemonBits

    SuperLemonBits

    Joined:
    Feb 28, 2016
    Posts:
    7
    Sorry I forgot to reply. That was SUPER useful, thanks a lot :)