How to fix this error in New input system
Help me solve this if it is outdated code as other 10 I wrote please send me some helpful not outdated videos or whatever i am working 5 days all day long and can't figure out how to do this.
Error message: InvalidOperationException: Cannot read value of type 'Single' from composite 'UnityEngine.InputSystem.Composites.Vector2Composite' bound to action 'Player/Move[/Keyboard/w,/Keyboard/s,/Keyboard/a,/Keyboard/d]' (composite is a 'Int32' with value type 'Vector2') UnityEngine.InputSystem.InputActionState.ReadValue[TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/com.unity.inputsystem@1.0.2/InputSystem/Actions/InputActionState.cs:1998) UnityEngine.InputSystem.InputAction.ReadValue[TValue] () (at Library/PackageCache/com.unity.inputsystem@1.0.2/InputSystem/Actions/InputAction.cs:934) PlayerController.Update () (at Assets/Scripts/InputSystem/PlayerController.cs:28)
Input Actions:
Input Actions Script:
// GENERATED AUTOMATICALLY FROM 'Assets/Scripts/InputSystem/PlayerControls.inputactions'
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class @PlayerActionControls : IInputActionCollection, IDisposable
{
public InputActionAsset asset { get; }
public @PlayerActionControls()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""PlayerControls"",
""maps"": [
{
""name"": ""Player"",
""id"": ""5ee2111e-8d58-4b62-8211-1802dd89e5fc"",
""actions"": [
{
""name"": ""Move"",
""type"": ""Value"",
""id"": ""e3b25e04-9ebf-4d93-938e-48e207e6bf88"",
""expectedControlType"": """",
""processors"": """",
""interactions"": """"
},
{
""name"": ""Jump"",
""type"": ""PassThrough"",
""id"": ""9dc6ce5d-ffb6-4889-baa5-d89630157223"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
}
],
""bindings"": [
{
""name"": ""2D Vector"",
""id"": ""bd92c46a-440f-46aa-b5d6-c1e84b90383c"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""a31dbfae-866b-433f-9ed3-fb78b2772f1d"",
""path"": ""<Keyboard>/w"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""c2d2aab8-ea94-49b6-9e5d-bca8bf2b3bf6"",
""path"": ""<Keyboard>/s"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""ea6c5b10-f732-407a-bcc5-07b693513adc"",
""path"": ""<Keyboard>/a"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""ac4447dc-f09b-4680-a2fc-7fb9eaf595bf"",
""path"": ""<Keyboard>/d"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": """",
""id"": ""8130f87f-3e8c-4cb0-8f97-75aa2303f001"",
""path"": ""<Keyboard>/space"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Jump"",
""isComposite"": false,
""isPartOfComposite"": false
}
]
}
],
""controlSchemes"": []
}");
// Player
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
m_Player_Move = m_Player.FindAction("Move", throwIfNotFound: true);
m_Player_Jump = m_Player.FindAction("Jump", throwIfNotFound: true);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
// Player
private readonly InputActionMap m_Player;
private IPlayerActions m_PlayerActionsCallbackInterface;
private readonly InputAction m_Player_Move;
private readonly InputAction m_Player_Jump;
public struct PlayerActions
{
private @PlayerActionControls m_Wrapper;
public PlayerActions(@PlayerActionControls wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Player_Move;
public InputAction @Jump => m_Wrapper.m_Player_Jump;
public InputActionMap Get() { return m_Wrapper.m_Player; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(PlayerActions set) { return set.Get(); }
public void SetCallbacks(IPlayerActions instance)
{
if (m_Wrapper.m_PlayerActionsCallbackInterface != null)
{
@Move.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMove;
@Move.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMove;
@Move.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnMove;
@Jump.started -= m_Wrapper.m_PlayerActionsCallbackInterface.OnJump;
@Jump.performed -= m_Wrapper.m_PlayerActionsCallbackInterface.OnJump;
@Jump.canceled -= m_Wrapper.m_PlayerActionsCallbackInterface.OnJump;
}
m_Wrapper.m_PlayerActionsCallbackInterface = instance;
if (instance != null)
{
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Jump.started += instance.OnJump;
@Jump.performed += instance.OnJump;
@Jump.canceled += instance.OnJump;
}
}
}
public PlayerActions @Player => new PlayerActions(this);
public interface IPlayerActions
{
void OnMove(InputAction.CallbackContext context);
void OnJump(InputAction.CallbackContext context);
}
}
Player Controler Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour{
private PlayerActionControls playerActionControls;
[SerializeField] private float speed, jumpSpeed;
private void Awake(){
playerActionControls = new PlayerActionControls();
}
private void OnEnable(){
playerActionControls.Enable();
}
private void OnDisable(){
playerActionControls.Disable();
}
void Start(){
}
void Update(){
float movementInput = playerActionControls.Player.Move.ReadValue<float>();
Vector3 currentPosition = transform.position;
currentPosition.x += movementInput * speed * Time.deltaTime;
transform.position = currentPosition;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613024926im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I give the player free flight? 1 Answer
Third person Camera rotation problem 2 Answers
I can't Jump and Run (3D) 0 Answers