Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Input System' started by GaZnoDrone, May 20, 2020.

  1. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5. using Zenject;
    6.  
    7. public class MoveSystem : MonoBehaviour, IMove
    8. {
    9.     public bool BEnableInput { get; private set; }
    10.  
    11.     public Vector2 Vec2Move { get; private set; }
    12.  
    13.     private InputController m_refInputControls;
    14.     private IUserControl m_refUserControl;
    15.  
    16.     [SerializeField]
    17.     private float m_fwalkSpeed = 5;
    18.  
    19.     [Inject]
    20.     void Init(InputController a_refInputControls)
    21.     {
    22.         Debug.Log("[MoveSystem] Init");
    23.  
    24.         m_refInputControls = a_refInputControls;
    25.         m_refInputControls.Player.Enable();
    26.         m_refInputControls.Player.Move.performed += Move;
    27.     }
    28.  
    29.     void OnEnable()
    30.     {
    31.         m_refUserControl = GetComponent<IUserControl>();
    32.         m_refUserControl.RegisterToEvent(UserSwitchedControl);
    33.     }
    34.  
    35.     void OnDisable()
    36.     {
    37.         if (m_refUserControl == null)
    38.             return;
    39.  
    40.         m_refUserControl.DeRegisterToEvent(UserSwitchedControl);
    41.     }
    42.  
    43.     void UserSwitchedControl()
    44.     {
    45.         BEnableInput = false;
    46.         Debug.Log("[MoveSystem] Switched Controls ");
    47.     }
    48.     // Start is called before the first frame update
    49.     void Start()
    50.     {
    51.         Vec2Move = Vector3.zero;
    52.     }
    53.  
    54.     // Update is called once per frame
    55.     void Update()
    56.     {
    57.         transform.Translate(new Vector3(Vec2Move.x, 0, Vec2Move.y) * Time.deltaTime * m_fwalkSpeed, Space.Self);
    58.     }
    59.  
    60.     public void Move(InputAction.CallbackContext callbackContext)
    61.     {
    62.         BEnableInput = true;
    63.         Vec2Move = callbackContext.ReadValue<Vector2>().normalized;
    64.         //Debug.Log("Move Input: " + Vec2Move);
    65.     }
    66. }
    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.
     

    Attached Files:

  2. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    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.
     
  3. Deleted User

    Deleted User

    Guest

  4. GaZnoDrone

    GaZnoDrone

    Joined:
    Mar 3, 2015
    Posts:
    28
    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
     
    Wesker911 likes this.
  5. Wesker911

    Wesker911

    Joined:
    Jun 5, 2014
    Posts:
    1
    Saved me a headache, thank you.
     
  6. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    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.
     
  7. RipInPixels

    RipInPixels

    Joined:
    Feb 23, 2021
    Posts:
    1
    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.
     
    Last edited: Jan 30, 2023