Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted 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. AbsurdAndy

    AbsurdAndy

    Joined:
    Dec 6, 2019
    Posts:
    20
  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
     
unityunity