Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Migrating to the new Input System

Discussion in 'Input System' started by huaffinity, May 15, 2020.

  1. huaffinity


    Oct 28, 2016
    Code (CSharp):
    1.     Vector2 dirInput;
    3.     private void OnEnable()
    4.     {
    5.         var control = m_Input.m_Controls;
    7.         control.Player.Movement.performed += HandleDirectionalInput;
    8.         control.Player.Movement.Enable();
    9.     }
    11.     private void HandleDirectionalInput(InputAction.CallbackContext ctx)
    12.     {
    13.         var value = ctx.ReadValue<Vector2>();
    14.         dirInput = value;
    15.     }
    17.     private Vector2 GetInputMovement()
    18.     {
    19.         //if (m_Input.m_Controls.Player.Movement.)
    20.         //{
    21.         //    return ClampMovementInput(dirInput);
    22.         //}
    23.         //else
    24.         //{
    25.         //    return;
    26.         //}
    27.         return dirInput;
    28.     }
    I had only one question, but as I tested this another came up.

    Where `control.Player.Movement` is ControlType Axis and CompositeType 2D Vector:

    1. With the code block above(no matter what the returned value does) dirInput stay indefinitely what it's given at the initial input. What I mean by that is that it never returns to as if I'm still holding the input when I'm not. Changing the direction works, but only then dirInput value changes and stays again. meaning whenever dirInput's value is changed it stays that way until given another input toward different direction.

    2. From what I've observed with question 1's case I wanted to condition it as shown commented out in GetInputMovement(), but I've tested every filed in ctx which I thought might flag the input is not being inputted, but found out that wasn't it unless I really missed something.

    I'm almost wanting to quit trying and go back to legacy, but knowing it'll be obsolete later I can't stop trying, but I need help on this.

    My best guess at the moment is not only I'm failing to achieve what I want here by missing out some core concept of the new system, or by misdirection. Please ask questions if I wasn't clear enough so that I can try better.

    Edit#1 Problem 1 solved via using
    instead of
    . Not sure that's how it was intended to be used, but works for now

    Code (CSharp):
    1. control.Player.Movement.started += HandleDirectionalInput;
    2.         control.Player.Movement.canceled += HandleDirectionalInput;
    Still wondering about the 2nd question
    Last edited: May 15, 2020