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

Resolved Can't read Vector2 from composite

Discussion in 'Input System' started by Jens00, Mar 7, 2024.

  1. Jens00

    Jens00

    Joined:
    Apr 26, 2017
    Posts:
    4
    Hello,

    I'm switching from the old inmut system to the new one but after 6 tutorials and a few demo scenes I'm still not able to get it to work and getting the following error each time.


    InvalidOperationException: Cannot read value of type 'Vector2' from composite 'UnityEngine.InputSystem.Composites.Vector2Composite' bound to action

    Code (CSharp):
    1. public void Move(InputAction.CallbackContext context)
    2. {
    3.     Debug.Log(context);
    4.     Debug.Log(context.ReadValue<Vector2>()); //Error is on this line
    5. }
    Screenshot_1.jpg

    Screenshot_2.jpg
     
  2. Jens00

    Jens00

    Joined:
    Apr 26, 2017
    Posts:
    4
    I was using System.Math but imported the package and it seems like that contains another vector2 wich doesn't wok with the composite one. But by using System.Math instead of Math fixed everything
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,230
    Fairly certain you ought to be using Unity's
    UnityEngine.Vector2
    struct.