New Input System InputValue being unused

Hello,

I want to ask a question on Rick implementation OnJump(InputValue value) and OnFire(InputValue value)

On one occasion (OnJump) we check value.isPressed to perform an action, whereas OnFire we never check the isPressed, but the code still works?

Since these methods use the message behavior, why we use the value argument on the one but not the other?

Thank you in advance

The argument is just data coming in. We can use it or ignore it. In one case we wanted to know if the button was pressed, and in the other we didn’t care.

For me at least it does not make sense.

Since OnJump and OnFire are similar, we can either omit on both methods the use of the value.isPressed, because the built in method knows that we have pressed the respective button, or we are forced to include the use of the isPressed.

Which one is it :slight_smile: ?

You can’t omit it. The method has a signature and that signature matters. If it is OnJump(InputValue value), then that’s what you need to match. You cannot just decide to use OnJump(). Nothing is going to call OnJump() because that’s not what the input system uses. The input system is going to call OnJump(InputValue value). If it’s not there, it will not call it

Ok we keep the signature, but can we omit the value.isPessed inside the code block on both of them? (OnJump and OnFire)

You can, but that changes the logic. These methods get called for each state change of the input. When the ‘Jump’ button is pressed, the input system calls the method. When the ‘Jump’ button is released, the input system also calls the method. We only want to jump when the button is pressed, which is why we check if the state isPressed. In the case of Fire, the bullets are created when you press the button and also when you release the button.

Hello,

Tested the functionality of the game with the signture just being OnJump() and OnFire() (no argument) and it still works!

I think of it similar to OnTriggerEnter2D(Collider2D other) where we can use the argument Collider2D other or not.

Perhaps the isPressed value is useful in cases when we want to log the exact moment the user presses the button, but keeps the functinoality of the action the same. Therefore, we can omit the use of the value argument.

I think the new input system with each button press messages the press down of the key, the release of the key and the execution of the action.

I do not think that the overall functionality of the e.g. jump action changes.

:open_mouth: TIL

Hahaha
:smiley:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms