How do I use interactions properly? -- Performed seems to be true every time button is pressed

I am trying to do very basic functionality where when the space bar is tapped the player does a single jump and when pressed the player does a double jump. I have tried multiple different way without getting desired functionality.

The closet I came was using something like…

    public void OnJump(InputAction.CallbackContext context)
    {         
      
        if (context.interaction is TapInteraction && _currState == IdleState)
        {
            JumnpState.doubleJump = false;       
            TransitionToState(JumpState);
        }
        if (context.interaction is PressInteraction && _currState == IdleState)
        {
            JumnpState.doubleJump = true;
            TransitionToState(JumpState);
        }

    }

however despite the Press being set to press only in the Input Actions it only triggers once I release the space bar.

The documentation is written such that it sounds like performed evaluates to True when the interaction on that action is completed however. The behaviour I get is performed evaluates to true when the button is pressed. i.e. seems to be having the same was as context.started

I’m not sure where I am going wrong. Set-up in my awake method is as follows

        playerInput = new PlayerInput();
        playerInput.PlayerControls.SetCallbacks(this);

where PlayerInput is the name of the Action Input.
Unity Version is 2019.3 and Input System Version 1.0

I believe you will need to have two different actions for the space key in your Input Actions Asset. For Double Jump, you will need to add a Hold interaction, where you can specify the hold time to trigger the action.

For your reference:

Thanks, I will try this today with the Hold interaction. I did try two different actions yesterday one with press and one with tap but again even though press was “Press Only” double jump would be triggered on release

I just was looking over a comment on youtube from 2 months ago and as of then, there was issues still with binding more than 1 action to the same button.

Example, if you have an action triggered by “B” and another one triggered by “Shift + B” when you hit shift the standard “B” button action is still triggered. This could be part of the problem as it seems like there’s no definitive list of features that are just “there” and don’t actually work yet.

On a side note, I went about handling my input slightly differently.

        public void Initialize()
        {
            if (_inputMap == null)
                _inputMap = new InputMap();

            _inputMap.Player.Move.Enable();
            _inputMap.Player.ShiftModifier.Enable();
            _inputMap.Player.ShiftModifier.performed += ctx => ShiftModifier = true;
            _inputMap.Player.ShiftModifier.canceled += ctx => ShiftModifier = false;
            _inputMap.Player.Move.performed += ctx => RawInput = ctx.ReadValue<Vector2>().normalized * movementSensitivity;
            _inputMap.Player.Move.canceled += ctx => RawInput = Vector2.zero;
        }
1 Like

I was able to get the it to function the way I wanted using hold, so that’s nice. Was also thinking of giving something like this a shot i.e. customization that I want in script

1 Like