Reputation: 1164
I'm trying to map my Dual Shock 4 controller with the new input system, but I'm getting this error:
InvalidOperationException: Cannot read value of type 'float' from control '/DualShock4GamepadHID/leftStick' bound to action 'Gameplay/Movement[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d,/DualShock4GamepadHID/leftStick,/DualShock4GamepadHID/leftStick,/DualShock4GamepadHID/leftStick,/DualShock4GamepadHID/leftStick]' (control is a 'StickControl' with value type 'Vector2')
UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionState.cs:1929)
UnityEngine.InputSystem.InputActionState.ReadCompositePartValue[TValue,TComparer] (System.Int32 bindingIndex, System.Int32 partNumber, System.Boolean* buttonValuePtr, System.Int32& controlIndex, TComparer comparer) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionState.cs:2010)
UnityEngine.InputSystem.InputBindingCompositeContext.ReadValueAsButton (System.Int32 partNumber) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputBindingCompositeContext.cs:252)
UnityEngine.InputSystem.Composites.Vector2Composite.ReadValue (UnityEngine.InputSystem.InputBindingCompositeContext& context) (at Library/PackageCache/[email protected]/InputSystem/Actions/Composites/Vector2Composite.cs:72)
UnityEngine.InputSystem.Composites.Vector2Composite.EvaluateMagnitude (UnityEngine.InputSystem.InputBindingCompositeContext& context) (at Library/PackageCache/[email protected]/InputSystem/Actions/Composites/Vector2Composite.cs:83)
UnityEngine.InputSystem.InputActionState.ComputeMagnitude (System.Int32 bindingIndex, System.Int32 controlIndex) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionState.cs:1826)
UnityEngine.InputSystem.InputActionState.ShouldIgnoreControlStateChange (UnityEngine.InputSystem.InputActionState+TriggerState& trigger, System.Int32 actionIndex) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionState.cs:984)
UnityEngine.InputSystem.InputActionState.ProcessControlStateChange (System.Int32 mapIndex, System.Int32 controlIndex, System.Int32 bindingIndex, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionState.cs:875)
UnityEngine.InputSystem.InputActionState.UnityEngine.InputSystem.LowLevel.IInputStateChangeMonitor.NotifyControlStateChanged (UnityEngine.InputSystem.InputControl control, System.Double time, UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, System.Int64 mapControlAndBindingIndex) (at Library/PackageCache/[email protected]/InputSystem/Actions/InputActionState.cs:783)
UnityEngine.InputSystem.InputManager.FireStateChangeNotifications (System.Int32 deviceIndex, System.Double internalTime, UnityEngine.InputSystem.LowLevel.InputEvent* eventPtr) (at Library/PackageCache/[email protected]/InputSystem/InputManager.cs:2687)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:120)
The WASD keys works but my controller does not.
That is my script:
using UnityEngine;
using UnityEngine.InputSystem;
public class CubeMovement : MonoBehaviour, PlayerControls.IGameplayActions
{
private PlayerControls m_PlayerControls;
private Vector2 m_Direction;
[SerializeField] private float movementVelocity;
private void Awake()
{
m_Direction = Vector2.zero;
m_PlayerControls = new PlayerControls();
m_PlayerControls.Gameplay.SetCallbacks(this);
}
private void Update()
{
var direction = Time.deltaTime * new Vector3(m_Direction.x, 0, m_Direction.y);
transform.Translate(direction);
}
public void OnMovement(InputAction.CallbackContext context)
{
m_Direction = movementVelocity * context.ReadValue<Vector2>();
}
private void OnEnable()
{
m_PlayerControls.Gameplay.Enable();
}
private void OnDisable()
{
m_PlayerControls.Gameplay.Disable();
}
}
That is my configuration:
I cannot found any solution on the web. Seems like I'm the first one with this problem.
Upvotes: 0
Views: 6168
Reputation: 11
To add to the answer above - to get the Sticks to register as available input for a binding, the Action also has to be set as "Pass Through" and "Vector 2"
Upvotes: 1
Reputation: 1164
I've found the solution. The correct way to map a stick is using the simple binding instead of 2D vector composite.
Upvotes: 1