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

Question Input system doesn't seem to be recognizing control type properly?

Discussion in 'Input System' started by PraetorBlue, Sep 2, 2020.

  1. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,935
    I have an action defined as:

    Action Type: "Value"
    Control Type: "Integer"

    It's bound to a couple of buttons on my gamepad:

    upload_2020-9-2_12-47-3.png

    Then in my code I'm trying to read the value of the input as an int:

    Code (CSharp):
    1. int stabilize = stabilizeAction.ReadValue<int>();
    2. Debug.Log($"Stabilize: {stabilize}");
    When I press the button, I get an exception:

    Code (CSharp):
    1. InvalidOperationException: Cannot read value of type 'int' from control '/XInputControllerWindows/rightShoulder' bound to action 'Drone/Stabilize[/XInputControllerWindows/leftShoulder,/XInputControllerWindows/rightShoulder]' (control is a 'ButtonControl' with value type 'float')
    2. UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Actions/InputActionState.cs:2020)
    3. UnityEngine.InputSystem.InputAction.ReadValue[TValue] () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Actions/InputAction.cs:934)
    4. Com.SadnessMonday.Drone.DroneControl.ProcessInput () (at Assets/Scripts/DroneControl.cs:248)
    5. Com.SadnessMonday.Drone.DroneControl.Update () (at Assets/Scripts/DroneControl.cs:223)
    It seems like Unity thinks the control is set as a ButtonControl with type float? What am I doing wrong?
     
    filip-mixedworld likes this.
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,935
    I opted to make it a normal Button control and just go event-based. But I feel like making an int-value-based button should work. Is that not supported?
     
    filip-mixedworld likes this.