Input system is switching between control schemes constantly

Sorry about the bad resolution

Hi everyone,
I have a problem when using the gamepad on my computer it switches randomly in and out of the gamepad control scheme I have no idea why its doing it and I’ve never had issues like this before (I don’t think) so if anyone knows how to fix this please help

Heres the Input Actions Manager: Link

Heres my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Users;

public class PlayerController : MonoBehaviour
{
    [SerializeField] private Rigidbody _rb;
    [SerializeField] private Vector2 playerMoveInput, playerLookInput;
    [SerializeField] private float speed, startingPos;

    public float pitch, roll;

    // Start is called before the first frame update
    void Awake()
    {
        _rb = GetComponent<Rigidbody>();

        Cursor.visible = false;
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        _rb.AddForce(
            (playerMoveInput.x + playerMoveInput.y) * speed * _rb.mass * Time.deltaTime,
            0,
            (playerMoveInput.y - playerMoveInput.x) * speed * _rb.mass * Time.deltaTime,
            ForceMode.Impulse);

        pitch = (transform.position.x + playerLookInput.x) - transform.position.x;
        roll = (transform.position.y + playerLookInput.y) - transform.position.y;

        // Wrap the pitch and roll values back to the range [-180, 180]
        // Makes sure that the values dont get too large when the object rotates
        pitch = Mathf.Repeat(pitch + 180, 360) - 180;
        roll = Mathf.Repeat(-roll + 180, 360) - 180;

        // Makes it so that these values are always in the opposite direction of the rotation
        roll *= -1;

        // Prevents some shitty error
        if (pitch != 0 || roll != 0)
        {
            Quaternion rot = Quaternion.LookRotation(new Vector3(-pitch, 0, -roll), Vector3.up);
            rot = Quaternion.Euler(0, startingPos, 0) * rot;
            transform.rotation = Quaternion.Lerp(transform.rotation, rot, 0.1f);
        }
    }

    public void Move(InputAction.CallbackContext context)
    {
        playerMoveInput = context.ReadValue<Vector2>();
    }
    public void Look(InputAction.CallbackContext context)
    {
        playerLookInput = context.ReadValue<Vector2>();
    }
}

What’s that XInput controller that is connected? This kind of stuff often happens when there is a device spamming the system with noise. For gamepads with sensors (such as the PS4 controller), sensor input is explicitly marked as noise and ignored in this context but a gamepad that’s constantly spamming minuscule changes in stick input would get past the noise detection and masquerade as actual input.

The controller that is connect is an Xbox controller, Would you know any ways I could stop this from happening?

I had this same problem, and after looking at other articles I found something that works: Add the gamepad to the keyboard/mouse control scheme. Go to the list of control schemes in your input actions file, select “Keyboard&Mouse”, select “Edit Control Scheme”. You should see a list that you can add to, already containing keyboard and mouse. Add gamepad to that list.

The end result is that the game no longer swaps back and forth between control schemes (which was causing a bunch of input problems for me). It does nothing to solve the root issue, of course.

1 Like

You just save my day and my headache !

For some reasons it was switching to touch scheme, i added keyboard and mouse to this scheme and voilà !

Big thanks =)