Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Problems with override rebinds

Discussion in 'Input System' started by Herooik, Jan 13, 2021.

  1. Herooik

    Herooik

    Joined:
    Oct 5, 2018
    Posts:
    5
    Hello. I followed the video about the new input system and I init this into my project but I got problems with rebindings keys.
    Example: My interact input is on the "E" key, and my crouch input is on the "C" key. When I perform interactive rebinding on crouch input and I press the "E" key there are errors. If I rebind the crouch input on the not occupied key everything works. So basically If I perform rebind on already occupied input there are errors.

    The error is made by "currentBindingInput" because "controlBindingIndex" is -1. I don't know why it happens.

    Code (CSharp):
    1. private void UpdateBindingDisplayUI()
    2.      {
    3.          int controlBindingIndex = _inputAction.GetBindingIndexForControl(_inputAction.controls[0]);
    4.          var currentBindingInput = InputControlPath.ToHumanReadableString(_inputAction.bindings[controlBindingIndex].effectivePath,
    5.              InputControlPath.HumanReadableStringOptions.OmitDevice);
    6.        
    7.          Sprite currentDisplayIcon = deviceDisplaySettings.GetDeviceBindingIcon(_playerInput, currentBindingInput);
    8.          ToggleGameObjectState(bindingIconDisplayImage.gameObject, true);
    9.          bindingIconDisplayImage.sprite = currentDisplayIcon;
    10.      }
     

    Attached Files:

    • 2.png
      2.png
      File size:
      96.2 KB
      Views:
      275
    • 1.png
      1.png
      File size:
      12.4 KB
      Views:
      287
  2. Saucyminator

    Saucyminator

    Joined:
    Nov 23, 2015
    Posts:
    61
    Sorry for the necro but I also stumbled upon this issue as well after following Warriors Input video (
    ).

    The issue seems to be fixed in 1.1.0-pre.5 (maybe earlier, this is the version I just tested).

    I've tested simple scene with a gameobject with PlayerInputManager calling Test() function:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class TestActions : MonoBehaviour {
    5.   public void Test (PlayerInput _input) {
    6.     Func("Join game", _input);
    7.     Func("Leave game", _input);
    8.   }
    9.  
    10.   private void Func (string _action, PlayerInput _input) {
    11.     var foundAction = _input.actions.FindAction(_action);
    12.     Debug.Log($"{_action} action: {foundAction}");
    13.     int index = foundAction.GetBindingIndexForControl(foundAction.controls[0]);
    14.     Debug.Log($"{_action} index: {index}");
    15.   }
    16. }
    Results were InputSystem 1.0.2 always returned index -1 if I had two actions assigned to the same binding.

    Index is correctly returned in the 1.1.0-pre.5 version.
     

    Attached Files: