Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question PlayerInput Component doesn't send messages after ActionRebind

Discussion in 'Input System' started by SchmidtDavidSimon, Dec 7, 2020.

  1. SchmidtDavidSimon

    SchmidtDavidSimon

    Joined:
    Sep 7, 2020
    Posts:
    13
    Hello everyone,
    I'm currently working on a metroid-vania game and decided to switch to the new input system. I set up a InputAsset: IS.png
    And build an ActionRebind Script according to the one in the TANKS game:
    Code (CSharp):
    1. public class ActionRebind : MonoBehaviour
    2. {
    3.     [SerializeField] private InputActionReference actionReference;
    4.     [Space]
    5.     [SerializeField] private TextMeshProUGUI actionName;
    6.     [SerializeField] private Button rebindButton;
    7.     [SerializeField] private TextMeshProUGUI actionText;
    8.     [SerializeField] private bool isGamepadSettings;
    9.    
    10.     private InputAction _action;
    11.     private InputActionRebindingExtensions.RebindingOperation _rebindOperation;
    12.  
    13.     private void Start()
    14.     {
    15.         _action = actionReference.action;
    16.         actionName.text = _action.name;
    17.         rebindButton.onClick.AddListener(delegate { RemapButtonClicked(_action.name); });
    18.         ResetButtonMappingTextValue();
    19.     }
    20.  
    21.     private void ResetButtonMappingTextValue()
    22.     {
    23.         actionText.text = InputControlPath.ToHumanReadableString(_action.bindings[isGamepadSettings ? 1 : 0].effectivePath);
    24.         rebindButton.gameObject.SetActive(true);
    25.     }
    26.  
    27.     private void RemapButtonClicked(string actionNameString)
    28.     {
    29.         rebindButton.enabled = false;
    30.         actionText.text = $"Press button / stick for" + actionNameString;
    31.         SetPlayerInputEnabled(false);
    32.         _rebindOperation?.Dispose();
    33.         _rebindOperation = _action.PerformInteractiveRebinding(isGamepadSettings ? 1 : 0)
    34.             .WithControlsExcluding("<Mouse>/position")
    35.             .WithControlsExcluding("<Mouse>/delta")
    36.             .OnMatchWaitForAnother(0.1f)
    37.             .OnComplete(operation => ButtonRebindCompleted());
    38.         _rebindOperation.Start();
    39.     }
    40.  
    41.     private void SetPlayerInputEnabled(bool value)
    42.     {
    43.         foreach (var playerInput in FindObjectsOfType<PlayerInput>())
    44.         {
    45.             playerInput.enabled = value;
    46.         }
    47.     }
    48.  
    49.     private void ButtonRebindCompleted()
    50.     {
    51.         _rebindOperation.Dispose();
    52.         _rebindOperation = null;
    53.         ResetButtonMappingTextValue();
    54.         rebindButton.enabled = true;
    55.         SetPlayerInputEnabled(true);
    56.     }
    57.  
    58.     private void OnDestroy()
    59.     {
    60.         _rebindOperation?.Dispose();
    61.     }
    62. }
    Everything used to work fine, but now for some reason after I rebind some of my inputs (for some it miraculously works) the PlayerInput component isn't sending messages when using the newly assigned path, but instead is still referring to the old path. At first I thought the ActionRebindAction just doesn't fully complete, but after creating some DebugLogs I saw, that it indeed finished as planed, and the new bound key was also shown as the path.

    Even with version control I can't seem to find a difference in when it worked and when it didn't so I'm asking for help here.

    Thanks in advance