Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Can't get a value from delta/Mouse after code refactor.

Discussion in 'Input System' started by Nathanieljla, Nov 13, 2020.

  1. Nathanieljla


    Apr 18, 2014
    I had my own UserInput component which handled mouse vs game controller input just fine. I then discovered the PlayerInput component and wanted to refactor my code to use this instead. And while I haven't changed much I can no longer get a value for mouse delta. The vector is always 0,0 Here's how my code's laid out.

    The old code during update (this worked):
    Code (CSharp):
    1. var lookAmount = _controls.PlayerCharacter.Look.ReadValue<Vector2>();
    new code (Doesn't work):
    Code (CSharp):
    1. //During Start()
    2. m_lookAction = m_playerInput.currentActionMap.FindAction(ACTION_NAME_LOOK);
    4. //During Update
    5. var lookAmount = m_lookAction.ReadValue<Vector2>();
    The Look action contains two binding and wasn't touched during the refactoring.
    Action Look:
    Action Type : Value
    Control Type : Vector2

    Path : Delta [mouse]
    Path : Right Stick [Gamepad]

    I must be missing something obvious here. Someone, please school me! I'm guessing it has something to do with the action getting the value from the controller vs the mouse. I did set the PlayerInput to the keyboard scheme to force it to ignore the controller, but still nothing.

    Thanks for the help,
  2. Nathanieljla


    Apr 18, 2014
    Fresh morning and a fresh head, fixed my issue. I'm still not sure why it worked in my previous case, but not this one.
    I had two actions dealing with the input. I nuked one and now it's working. I do see people using rather than action.ReadValue<Vector2>() Is there a benefit to one over the other?
    Last edited: Nov 14, 2020