On releasing input, the value isnt reset to (0,0) when reading from callback context

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using Zenject;

public class MoveSystem : MonoBehaviour, IMove
{
    public bool BEnableInput { get; private set; }

    public Vector2 Vec2Move { get; private set; }

    private InputController m_refInputControls;
    private IUserControl m_refUserControl;

    [SerializeField]
    private float m_fwalkSpeed = 5;

    [Inject]
    void Init(InputController a_refInputControls)
    {
        Debug.Log("[MoveSystem] Init");

        m_refInputControls = a_refInputControls;
        m_refInputControls.Player.Enable();
        m_refInputControls.Player.Move.performed += Move;
    }

    void OnEnable()
    {
        m_refUserControl = GetComponent<IUserControl>();
        m_refUserControl.RegisterToEvent(UserSwitchedControl);
    }

    void OnDisable()
    {
        if (m_refUserControl == null)
            return;

        m_refUserControl.DeRegisterToEvent(UserSwitchedControl);
    }

    void UserSwitchedControl()
    {
        BEnableInput = false;
        Debug.Log("[MoveSystem] Switched Controls ");
    }
    // Start is called before the first frame update
    void Start()
    {
        Vec2Move = Vector3.zero;
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(new Vector3(Vec2Move.x, 0, Vec2Move.y) * Time.deltaTime * m_fwalkSpeed, Space.Self);
    }

    public void Move(InputAction.CallbackContext callbackContext)
    {
        BEnableInput = true;
        Vec2Move = callbackContext.ReadValue<Vector2>().normalized;
        //Debug.Log("Move Input: " + Vec2Move);
    }
}

I have implemented a simple movement system just to see how well Input System works nothing fancy.
What I have noticed is when I log the context value I never get (0,0) on stopping all inputs. I have a keyboard mouse and gamepad connected.
I have seen older tutorial videos they seem to log (0,0) when input is released.

I am using the default ActionMaps, not created new actionmaps/actions. I have upladed images of the Actions setup in the editor. The C# is already generated.

5875582--625621--InputController_01.jpg
5875582--625624--InputController_02.jpg
5875582--625627--InputController_03.jpg
5875582--625630--InputController_04.jpg

After switching type to pass through it seems to have worked. I am using 2019.3.5f1, it could be a bug not sure. Value type should have worked.
I will be updating my unity version and will confirm here if it was a unity version bug.

I ran into this as well, and posted about it here:

As a workaround, if you listen to the .canceled event, you’ll get the 0,0 values reported in there.

I actually tried that too for some reason it didn’t work for me, the only thing that worked was changing value type to pass through. Thanks for the response, appreciate it.

PS: updating the unity version didn’t help either

1 Like

Saved me a headache, thank you.

1 Like

Doesn’t work in 1.3.0
Reading the value from the canceled event gives you the last input value, not the default. This is contrary to the behaviour specified in the documentation.

Oh my goodness thank you! I thought I was losing it. Don’t know if I’m doing anything wrong, but I’m still having this issue on 2021.3.16f

edit: Switching to Pass Through did fix it for now.

1 Like