Creating GetButtonDown style Inputs with the Input system

Hey guys I’m new here. I recently switched over to the Input System after running into bugs with the old Input Manager and I’m having some trouble replicating the behavior of the GetKeyDown method, using a singleton to handle inputs. Here’s my code.

string jumpPress = "jumpPress";
InputAction jumpPrsAct;
public bool jumpPrsInput {  get; private set; }
void Awake()
{        
jumpPrsAct = playerControls.FindActionMap(actionMapName).FindAction(jumpPress);
RegisterInputActions(); 
}
void RegisterInputActions()
    {
        jumpPrsAct.performed += context => jumpPrsInput = true;
        jumpPrsAct.canceled += context => jumpPrsInput = false;
    }

Stuff I’ve tried:

{
 jumpPrsAct.started+= context => jumpPrsInput = true;
  jumpPrsAct.performed+= context => jumpPrsInput = false;
}

*This just executes on the same update frame, instead of the desired one frame-after-another
Using the “Press Only” interaction is identical to the regular button action

I’m thinking that I need to access the callback context somehow but I’m having trouble learning how to do it. I can’t access context in the script that uses the controls because the action already seems to be packaged as a bool. Can someone walk me through this?

You can use it another way in the Update() function, which can give you more flexibility in terms of frame control.

using UnityEngine;
using UnityEngine.InputSystem;

public class Example : MonoBehaviour
{
    InputAction interactAction;

    private void Start()
    {
        interactAction = InputSystem.actions.FindAction("Interact");
    }

    void Update()
    {
        if (interactAction.WasPerformedThisFrame())
        {
            // your code to respond to the first frame that the Interact action is held for enough time
        }

        if (interactAction.WasCompletedThisFrame())
        {
            // your code to respond to the frame that the Interact action is released after being held for enough time
        }
    }
}

Thanks for the reply, I may end up needing to use this approach if I run into issues down the line.
For now, I just ended up removing the .canceled callback, checking if the bool is true inside the singleton’s update function and then using a next frame coroutine to set it back to false and it’s working nicely so far