Skip to main content
Cleanup
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

"Tell me!!" Error that occurs when moving with PlayerInput Cannot read value of type 'Vector3' error in UnityInput System package

I'm a Unity newbie. This time, I'm trying to make the Player operable with an Xbox controller using PlayerInput. However, when I control the player, I get about 4these errors. I've been struggling with it lately, so please let me know how to fix it.:

Errors that occurred:

[20:35:08] InvalidOperationException: Cannot read value of type 'Vector3' from control '/XinputControllerWindows/leftStick' bound to action 'Player/Move[/XInputControllerWindows/leftStick]'

[20:35:08] InvalidOperationException while execuring 'started' callbacks of 'Player/Move[/XInputControllerWindows/leftStick]'

Error messages

The version is 2021.3.37f1. The work is made with something called 3D Sample Scene (URP).

Errors that occurred enter image description herePlayerInput

PlayerInput enter image description hereInput configuration window

PlayerContoroller

using UnityEngine; using UnityEngine.InputSystem; using Vector2 = UnityEngine.Vector2; using Vector3 = UnityEngine.Vector3;

public class PlayerController_PC : MonoBehaviour { private Rigidbody rb; private Vector3 move; private Vector3 moveForward; [SerializeField] private float moveSpeed; [SerializeField] private float turnTimeRate = 0.5f;

// Start is called before the first frame update
void Start()
{
    rb = this.gameObject.GetComponent<Rigidbody>();
    rb.constraints = RigidbodyConstraints.FreezeRotation;
}

// Update is called once per frame
void Update()
{
    Move();
}

void FixedUpdate()
{
    Rotation();
}

private void Move()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        rb.velocity = moveForward * moveSpeed * move.magnitude + new Vector3(0, rb.velocity.y, 0);
    }
    else
    {
        rb.velocity = new Vector3(0, rb.velocity.y, 0);
    }
}

private void Rotation()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        Quaternion targetRotation = Quaternion.LookRotation(moveForward);
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnTimeRate);
    }
    else
    {
        Quaternion targetRotation = transform.rotation;
        transform.rotation = targetRotation;
    }
}

public void OnMove(InputAction.CallbackContext context)
{
    move = new Vector3(context.ReadValue<Vector3>().x, 0f, context.ReadValue<Vector2>().y);
}

}

Sorry for the long post

using UnityEngine;
using UnityEngine.InputSystem;
using Vector2 = UnityEngine.Vector2;
using Vector3 = UnityEngine.Vector3;

public class PlayerController_PC : MonoBehaviour
{
    private Rigidbody rb;
    private Vector3 move;
    private Vector3 moveForward;
    [SerializeField]
    private float moveSpeed;
    [SerializeField]
    private float turnTimeRate = 0.5f;

    // Start is called before the first frame update
    void Start()
    {
        rb = this.gameObject.GetComponent<Rigidbody>();
        rb.constraints = RigidbodyConstraints.FreezeRotation;
    }

    // Update is called once per frame
    void Update()
    {
        Move();
    }

    void FixedUpdate()
    {
        Rotation();
    }

    private void Move()
    {
        Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
        moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
        moveForward = moveForward.normalized;

        if (move.magnitude > 0)
        {
            rb.velocity = moveForward * moveSpeed * move.magnitude + new Vector3(0, rb.velocity.y, 0);
        }
        else
        {
            rb.velocity = new Vector3(0, rb.velocity.y, 0);
        }
    }

    private void Rotation()
    {
        Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
        moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
        moveForward = moveForward.normalized;

        if (move.magnitude > 0)
        {
            Quaternion targetRotation = Quaternion.LookRotation(moveForward);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnTimeRate);
        }
        else
        {
            Quaternion targetRotation = transform.rotation;
            transform.rotation = targetRotation;
        }
    }

    public void OnMove(InputAction.CallbackContext context)
    {
        move = new Vector3(context.ReadValue<Vector3>().x, 0f, context.ReadValue<Vector2>().y);
    }
}

"Tell me!!" Error that occurs when moving with PlayerInput in Unity

I'm a Unity newbie. This time, I'm trying to make the Player operable with an Xbox controller using PlayerInput. However, when I control the player, I get about 4 errors. I've been struggling with it lately, so please let me know how to fix it. The version is 2021.3.37f1. The work is made with something called 3D Sample Scene (URP).

Errors that occurred enter image description here

PlayerInput enter image description here

PlayerContoroller

using UnityEngine; using UnityEngine.InputSystem; using Vector2 = UnityEngine.Vector2; using Vector3 = UnityEngine.Vector3;

public class PlayerController_PC : MonoBehaviour { private Rigidbody rb; private Vector3 move; private Vector3 moveForward; [SerializeField] private float moveSpeed; [SerializeField] private float turnTimeRate = 0.5f;

// Start is called before the first frame update
void Start()
{
    rb = this.gameObject.GetComponent<Rigidbody>();
    rb.constraints = RigidbodyConstraints.FreezeRotation;
}

// Update is called once per frame
void Update()
{
    Move();
}

void FixedUpdate()
{
    Rotation();
}

private void Move()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        rb.velocity = moveForward * moveSpeed * move.magnitude + new Vector3(0, rb.velocity.y, 0);
    }
    else
    {
        rb.velocity = new Vector3(0, rb.velocity.y, 0);
    }
}

private void Rotation()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        Quaternion targetRotation = Quaternion.LookRotation(moveForward);
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnTimeRate);
    }
    else
    {
        Quaternion targetRotation = transform.rotation;
        transform.rotation = targetRotation;
    }
}

public void OnMove(InputAction.CallbackContext context)
{
    move = new Vector3(context.ReadValue<Vector3>().x, 0f, context.ReadValue<Vector2>().y);
}

}

Sorry for the long post

Cannot read value of type 'Vector3' error in Input System package

I'm a Unity newbie. This time, I'm trying to make the Player operable with an Xbox controller using PlayerInput. However, when I control the player, I get these errors:

Errors that occurred:

[20:35:08] InvalidOperationException: Cannot read value of type 'Vector3' from control '/XinputControllerWindows/leftStick' bound to action 'Player/Move[/XInputControllerWindows/leftStick]'

[20:35:08] InvalidOperationException while execuring 'started' callbacks of 'Player/Move[/XInputControllerWindows/leftStick]'

Error messages

The version is 2021.3.37f1. The work is made with something called 3D Sample Scene (URP).

PlayerInput

Input configuration window

PlayerContoroller

using UnityEngine;
using UnityEngine.InputSystem;
using Vector2 = UnityEngine.Vector2;
using Vector3 = UnityEngine.Vector3;

public class PlayerController_PC : MonoBehaviour
{
    private Rigidbody rb;
    private Vector3 move;
    private Vector3 moveForward;
    [SerializeField]
    private float moveSpeed;
    [SerializeField]
    private float turnTimeRate = 0.5f;

    // Start is called before the first frame update
    void Start()
    {
        rb = this.gameObject.GetComponent<Rigidbody>();
        rb.constraints = RigidbodyConstraints.FreezeRotation;
    }

    // Update is called once per frame
    void Update()
    {
        Move();
    }

    void FixedUpdate()
    {
        Rotation();
    }

    private void Move()
    {
        Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
        moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
        moveForward = moveForward.normalized;

        if (move.magnitude > 0)
        {
            rb.velocity = moveForward * moveSpeed * move.magnitude + new Vector3(0, rb.velocity.y, 0);
        }
        else
        {
            rb.velocity = new Vector3(0, rb.velocity.y, 0);
        }
    }

    private void Rotation()
    {
        Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
        moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
        moveForward = moveForward.normalized;

        if (move.magnitude > 0)
        {
            Quaternion targetRotation = Quaternion.LookRotation(moveForward);
            transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnTimeRate);
        }
        else
        {
            Quaternion targetRotation = transform.rotation;
            transform.rotation = targetRotation;
        }
    }

    public void OnMove(InputAction.CallbackContext context)
    {
        move = new Vector3(context.ReadValue<Vector3>().x, 0f, context.ReadValue<Vector2>().y);
    }
}
edited title
Link

"Tell me!!" Error that occurs when moving with PlayerInput in Unity

added 2075 characters in body; edited tags
Source Link

enter image description here using UnityEngine; using UnityEngine.InputSystem; using Vector2 = UnityEngine.Vector2; using Vector3 = UnityEngine.Vector3;

enter image description here public class PlayerController_PC : MonoBehaviour { private Rigidbody rb; private Vector3 move; private Vector3 moveForward; [SerializeField] private float moveSpeed; [SerializeField] private float turnTimeRate = 0.5f;

// Start is called before the first frame update
void Start()
{
    rb = this.gameObject.GetComponent<Rigidbody>();
    rb.constraints = RigidbodyConstraints.FreezeRotation;
}

// Update is called once per frame
void Update()
{
    Move();
}

void FixedUpdate()
{
    Rotation();
}

private void Move()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        rb.velocity = moveForward * moveSpeed * move.magnitude + new Vector3(0, rb.velocity.y, 0);
    }
    else
    {
        rb.velocity = new Vector3(0, rb.velocity.y, 0);
    }
}

private void Rotation()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        Quaternion targetRotation = Quaternion.LookRotation(moveForward);
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnTimeRate);
    }
    else
    {
        Quaternion targetRotation = transform.rotation;
        transform.rotation = targetRotation;
    }
}

public void OnMove(InputAction.CallbackContext context)
{
    move = new Vector3(context.ReadValue<Vector3>().x, 0f, context.ReadValue<Vector2>().y);
}

}

enter image description here

enter image description here

using UnityEngine; using UnityEngine.InputSystem; using Vector2 = UnityEngine.Vector2; using Vector3 = UnityEngine.Vector3;

public class PlayerController_PC : MonoBehaviour { private Rigidbody rb; private Vector3 move; private Vector3 moveForward; [SerializeField] private float moveSpeed; [SerializeField] private float turnTimeRate = 0.5f;

// Start is called before the first frame update
void Start()
{
    rb = this.gameObject.GetComponent<Rigidbody>();
    rb.constraints = RigidbodyConstraints.FreezeRotation;
}

// Update is called once per frame
void Update()
{
    Move();
}

void FixedUpdate()
{
    Rotation();
}

private void Move()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        rb.velocity = moveForward * moveSpeed * move.magnitude + new Vector3(0, rb.velocity.y, 0);
    }
    else
    {
        rb.velocity = new Vector3(0, rb.velocity.y, 0);
    }
}

private void Rotation()
{
    Vector3 cameraForward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized;
    moveForward = cameraForward * move.z + Camera.main.transform.right * move.x;
    moveForward = moveForward.normalized;

    if (move.magnitude > 0)
    {
        Quaternion targetRotation = Quaternion.LookRotation(moveForward);
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * turnTimeRate);
    }
    else
    {
        Quaternion targetRotation = transform.rotation;
        transform.rotation = targetRotation;
    }
}

public void OnMove(InputAction.CallbackContext context)
{
    move = new Vector3(context.ReadValue<Vector3>().x, 0f, context.ReadValue<Vector2>().y);
}

}

Source Link
Loading