Search Unity

Question PlayerInput SwitchCurrentControlScheme() doesn´t work :(

Discussion in 'Input System' started by FranForge, Dec 4, 2023.

  1. FranForge

    FranForge

    Joined:
    Mar 29, 2023
    Posts:
    2
    We are trying to create a local multiplayer game, for this I want to have control over which scheme to assign to each player at all times, I created a script to assign the control schemes but once it starts and changes the characters stop moving, this problem is already It drives me crazy, I've thought about it many times and this is the one that convinces me the most and in which at least it did something.
    Am I missing something to execute? Should I change something?
    Thank you very much in advance :D

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5.  
    6. public class ChangeCurrentInput : MonoBehaviour
    7. {
    8.     PlayerInput input;
    9.     string scheme = "Gamepad";
    10.  
    11.     void Awake()
    12.     {
    13.         input = GetComponent<PlayerInput>();
    14.  
    15.         if(input != null)
    16.         {
    17.             ChangeScheme();
    18.         }
    19.     }
    20.  
    21.     void ChangeScheme()
    22.     {
    23.         Debug.Log("Esquema de control actual (" + input.currentControlScheme + ")");
    24.  
    25.         input.DeactivateInput();
    26.         input.SwitchCurrentControlScheme(scheme);
    27.         input.ActivateInput();
    28.  
    29.         Debug.Log("Esquema de control cambiado (" + input.currentControlScheme + ")");
    30.     }
    31. }
    32.