Issue handling "Pressed" event for InputSystem using PlayerInput

Hey there,

I’m working on a local multiplayer game with multiple controllers, and because of that, I cannot do a simple check like “Keyboard.current[KeyCode.Space].wasPressedThisFrame”.

My player object is going to end up a bit complex, plus I’m used to breaking up the scripts into different controllers. Anim/Input/OverallController etc. So I cant work just of the fired event, I would like to access a stored boolean for the pressed button action.

On my ActionObject, I have an event tied with the Jump button. And a boolean that stores a reference to the “IsKeyPressed” condition of that. I also managed to get it to work with FixedUpdate.

See here:

public class CharacterInputHandler : MonoBehaviour
{
    public bool Jumped { get; set; }
    public bool JumpedFixed { get; set; }
    private bool jump = false;
  
    public void EventJump(CallbackContext ctx)
    {
        //IsKeyDown() is an extanetion method I made, just check if InputActionPhase.Started
        jump = ctx.IsKeyDown();
        if (jump)
        {
            Jumped = true;
            JumpedFixed = true;
        }
    }

    private void Update()
    {
        if (Jumped) Jumped = false;
    }

    private void FixedUpdate()
    {
        if (JumpedFixed) JumpedFixed = false;
    }
}

The issue is, it randomly stopped working for ages.
So I added a couple of extra booleans into my Update/FixedUpdate checks.
Like so…

bool jumpedFrameWaited = false;

private void FixedUpdate()
{
    if (JumpedFixed)
    {
        if (jumpedFrameWaited)
        {
            JumpedFixed = false;
        }
        jumpedFrameWaited = true;
    }
}

This worked for a bit, then started firing twice. As the other components were now ahead of the object in execution.

I don’t wanna mess with the execution order this early in development. Does anybody have any ideas?

I also tried the Tap interaction method but that is not accurate enough. A debug.log will show it stays true for too long, and at an inconsistent amount of frames so tweaking won’t work.

Any help would be greatly appreciated.

Ok this is just getting stupid :eyes:

So I have still been fiddling with this. I just decide to start from scratch and work my way up…

So I create an empty script and manually subscribe to the Jump action.
Then do a debug.log. The event triggered once.

If I add an object to the scene that has a PlayerInput component and access the event that way. it will fire twice.

And If I use the PlayerInputManager to instantiate a prefab of the above object. The event fires four times!!

I’m guessing the new input system is not stable yet?