Equivalent of Input.GetButton in new input system

So I think I’ve worked out GetButtonDown and GetButtonUp.

PlayerInput _playerInput;
InputAction _jumpAction;
InputAction _fireAction;

void Start() {
  var map = _playerInput.currentActionMap;
  _jumpAction = map.FindAction("Jump", true);
  _fireAction = map.FindAction("Fire", true); 
}

static bool IsDown(InputAction action) => action.phase == InputActionPhase.Performed;
static bool IsUp(InputAction action) => action.phase == InputActionPhase.Canceled;

void Update() {
  if (IsDown(_jumpAction)) {
    // Start jump
  } else if (IsUp(_jumpAction)) {
    // Release jump
  }

But how do we check if a button is held this frame, as opposed to just pressed?

Can I also just say that this API is a real pain to work with. If I’m not missing something events seem like the wrong choice for games where we want to manually poll input every frame, and order of execution is important. We’ve burned many hours just trying to implement a simple jump feature.

Also, even to just work out the above I had to do a deep dive into the scripting reference. I’m still not sure if it’s correct.

I solved this by using the player input generated On"xyz"() functions. I then set the input type to value. Value allows a floating-point number between 0 and 1 and will be called as long as it is greater than 0. Use a variable to store the InputValue and if it is greater than 1, the button is pressed. Also, if you have access to get button-down and get button-up, can’t you just have a bool that is set to false on up and true on down?

Trying to poll the state to avoid using events, and instead read the value directly. Are you saying that you used the Unity events system, or the new code generation system?

As of 1.1-pre.6.

myAction.WasPressedThisFrame();

myAction.WasReleasedThisFrame();

myAction.IsPressed();
2 Likes

there’s already a better answer, but yeah I used the unity event system.

Thanks!

Um… @Rene-Damm . It seems that the package manager doesn’t recognise that version because it doesn’t conform to semver.

An error occurred while resolving packages:
  Project has invalid dependencies:
    com.unity.inputsystem: Version '1.1-pre.6' is invalid. Expected one of: a 'SemVer' compatible value; a value starting with 'file:'; a Git URL starting with 'git:' or 'git+', or ending with '.git'.

A re-import of the project may be required to fix the issue or a manual modification of C:/Users/rhysv/Projects/Moball/Packages/manifest.json file.

Also new release marked on github repo is not available through registry?

7459156--915625--upload_2021-8-30_12-40-1.png

Furthermore the revision you mentioned is not even tagged in the repo…

7459171--915634--upload_2021-8-30_12-47-41.png

Okay, managed to update with this line:

    "com.unity.inputsystem": "git://github.com/Unity-Technologies/InputSystem.git?path=Packages/com.unity.inputsystem#1.1.0",

You can update through package manager this way . Just change the 5 to 6. It is working, no need for the git repo if you don’t want for something specifically.

1.1.0 is not available in the registry. Surely I should take stable version over pre.6 now that it’s on the repo?

It isn’t released yet.

But I’m a bit confused, in your previous post you tried to pull the 1.1-pre.6 version (but the version number you used is wrong) which should be 1.1.0-pre.6. That’s why I mentioned that you can install it through the package manager, just follow the link, I wrote it in details, step by step.

That would likely work. I just used the version number that @Rene-Damm gave me. However that was before the 1.1.0 “release” (although looking at the PR it doesn’t have test coverage yet). Either way I’ve burned enough time on this one. Thanks for the pointer for future. I’m pretty sure that UI interface is just the same as modifying the manifest.json directly in any case.

@ Actually, do you know how to get a list of releases? It seems they’re hidden in the package manager even if I have preview packages enabled. All this confusion could have been sidestepped if they were visible.

Yes, but how to use this in an if statement? Doesnt seem to work for me:P

so what is answer of original question?

what is same function code of old functions(GetButtonDown, GetButton, GetButtonUp)?

I recommend reading the guide migrating from the Input Manager. You can find it here: GetButton, GetButtonDown and GetButtonUp.

1 Like