D-pad input changes not responding

I’m setting up my game to use a controller. I just added the ability to use the D-pad to control the player. In my game the player only moves in four directions anyway. I’m using the new input system.

But sometimes I will change direction and the player won’t change; I move my thumb to press a new direction, but the player responds like I’m still holding down the old direction.
I’m not sure what the problem is; maybe I’m moving too fast, maybe I’m sliding my thumb, whatever the cause I can’t reproduce the effect 100% of the time, but it does seem to happen when I make quicker motions.

Has anyone else had a similar problem? This is a very critical issue to my gameplay; I can’t release a game where the player sometimes doesn’t respond to player input.

I don’t think this is a problem with my code, because it only happens with the D-pad. If I use the keyboard arrows, I can make all the quick motions and sliding I want without any problems.
But just to be sur, here’s the code for my input:

    void OnMove(InputValue value)
    {
        //Vector3 Movement = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")) * moveSpeed;
        Vector2 TwoMovement = value.Get<Vector2>();

        if (TwoMovement.magnitude < 0.1f)   // @@@  Aaaack!
        {
            Movement = Vector3.zero;
            Anim.SetAnimation(Animation.Idle);
            return;
        }

        if (bRunMode)
        {
            Anim.SetAnimation(Animation.Run);
        }
        else
        {
            Anim.SetAnimation(Animation.Walk);
        }
        if (Mathf.Abs(TwoMovement.x) > Mathf.Abs(TwoMovement.y))
        {
            //We are moving horizontal
            if (TwoMovement.x > 0)
            {
                Movement = Vector3.right * TwoMovement.magnitude;
            }
            else
            {
                Movement = Vector3.left * TwoMovement.magnitude;
            }
        }
        else
        {
            //We are moving vertical
            if (TwoMovement.y > 0)
            {
                Movement = Vector3.forward * TwoMovement.magnitude;
            }
            else
            {
                Movement = Vector3.back * TwoMovement.magnitude;
            }
        }

        if (bRunMode)
        {
            Movement *= RunSpeed;
        }
        else
        {
            Movement *= moveSpeed;
        }


        SetFacingAngle( Direction.VectorToDirection(Movement));
        Anim.UpdateFacingDirection(facingDirection);
    }

And then in FixedUpdate the Movement variable is fed into the character controller.

As you can see, I first check for a zero direction, and then find which of the four directions the player’s input is closest to, and then apply the input’s magnitude to that direction.

The character’s game object maintains the same rotation because it has a sprite that must face the camera; the “set Facing Angle” and “Anim” functions handle that.

Is there some property I am not setting in the Input Actions? Why is the D-pad sometimes not registering a change in its value?

Looks like you just swapped out line 3 and 4 above for old input to new input, so as you note, it likely isn’t code.

I would start with carefully inspecting (or even recreating afresh) the input action setup, you probably have something incorrectly setup.

For debugging, print the values and prove they work at the raw numeric stage, right after you collect them. If they don’t work there, they won’t work anywhere else.

… and now for my standard debugging blurb…

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.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

After a day it occurred to me that I had this problem in another project. I managed to track down a post I made about it four years ago.

The solution was shared by @munce (although I can’t respond to the original post anymore to thank him) and it is to create a new 2D vector composite for the D-pad instead of using the the default D-pad input.

This sounds like a problem with Unity that has never been resolved; so I suspect it isn’t very common.
I don’t know if the problem is with some oddly specific controllers not interfacing properly, or if not enough people are trying to use the D-pad to control gameplay.