[Solved] Quick Question About The New Input System

Hello, people. Just a quick question:

I’m using the new input system and so far everything is working great. I’ve set up a Move action (generic WASD movement, nothing new) and a HoldBreath action (triggered when holding down the mouse right button). What I’m trying to achieve is to move slower when the HoldBreath action is triggered. I’ve set up a variable that can detect this and it is being set to true/false correctly.

However, if I hold the mouse right button while moving, it doesn’t work. It only works when I stop moving and move again (with the right mouse button still being hold). It’s like the input system is keeping something in memory and only flushes it when I release the keyboard keys. Am I missing something?

I did a search about this topic but couldn’t find any solution for that. Doe anyone here have any thoughts?

Most likely you just wrote a bug.

If you think this:

then PROVE IT!

Simply spit the raw values out immediately after you get them from the input system.

You’ll find they’re (likely) correct and that the bug lies elsewhere.

That means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

if you DO find a discrepancy in actual input signals, consider possible hardware issues too:

Keyboard rollover, jammed keys, bad key combinations:

Test your keyboard here (hat tip to Ryiah!): Online Key Rollover Test - Mechanical Keyboard

Please only use the 2D tag when discussing 2D features. The Input System isn’t a 2D feature and has its own tag so I’ll modify that for you.

Thanks.

EDIT:

Nvm, I just fixed it.


Well, I did some testing before posting and it didn’t work, so that’s why I’m asking for some guidance.
And I didn’t even said it was a bug, I just said that it seems like there’s something in memory that is not being flushed. :thinking:

As for the Key rollover, I don’t think that’s the case. I tested with 2 keyboards and with both of them, no success.

I checked the player speed and it is indeed changing depending on the boolean, so I believe there doesn’t seem to be something wrong with the way I’m moving. But well, I might be wrong.
I even created a brand new player prefab without some of the original player child objects to test and well, no success.

This is how my Action Maps and Actions are organized:


I have a base InputReader class where I’m creating my GameInput (my input class) instance.

On my MovementInputReader class, I’ve set both OnEnable/OnDisable like this:

protected void OnEnable()
{
    base.OnEnable();
    gameInput.Player.Move.performed += OnMove;
    gameInput.Player.Move.canceled += OnMove;
}

protected void OnDisable()
{
    base.OnDisable();
    gameInput.Player.Move.performed -= OnMove;
    gameInput.Player.Move.canceled -= OnMove;
}

On my BreathControlInputReader, I have the following:

protected void OnEnable()
{
    base.OnEnable();
    gameInput.Player.BreathControl.performed += OnHoldBreath;
    gameInput.Player.BreathControl.canceled += OnRegenerateBreath;
}

protected void OnDisable()
{
    base.OnDisable();
    gameInput.Player.BreathControl.performed -= OnHoldBreath;
    gameInput.Player.BreathControl.canceled -= OnRegenerateBreath;
}

I’m not doing anything complicated for my logic. My MovementController has a FixedUpdate that gets the speed based on the boolean I mentioned before and sets it to true/false whether I’m holding my breath. Then I do some calculations regarding acceleration etc, and move the player using .AddForce().
As far as I’ve checked, everything is working perfectly fine and the calculations are using the right values. But for it to work, I have to release the movement key and press it again.