Search Unity

IndexOutOfRange on Axis Action

Discussion in 'Input System' started by ryanslikesocool, Dec 21, 2018.

  1. ryanslikesocool

    ryanslikesocool

    Joined:
    Jul 31, 2016
    Posts:
    49
    I'm really new to the new Input System so please forgive my ignorance. I'm trying to use an axis action and read that checking the value with
    ReadValue<int>()
    doesn't work, only with a Vector2, and that the Press interaction doesn't work with an axis, so I'm using the Stick interaciton. Whenever I press the corresponding button, I get this error.
    Screen Shot 2018-12-21 at 12.22.23 AM.png
    I'm not exactly sure where I'm going wrong. Here's the snippet of code where I'm checking the value.
    Code (CSharp):
    1.  
    2. public void OnHorizontal(InputAction.CallbackContext context)
    3.     {
    4.         Debug.Log(context.ReadValue<Vector2>());
    5.     }
    6. }
    And here is my input setup
    Screen Shot 2018-12-21 at 12.23.11 AM.png


    UPDATE:
    Turns out it was a silly error on my part. Using
    float
    instead of
    Vector2
    works. Sorry to be a bother!
     
    Last edited: Dec 21, 2018
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Filed a ticket here. Even if the value type is wrong, it shouldn't come up with an IndexOutOfRangeException but rather throw an exception that properly explains what the problem is. And, well, ideally the UI should prevent the setup in the first place. But oh well, we'll get there :)
     
  3. Albarnie

    Albarnie

    Joined:
    Oct 24, 2015
    Posts:
    18
    Had this issue too, the new update fixed it for me.
     
    Rene-Damm likes this.