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

Question How to effectively obtain Binding Index?

Discussion in 'Input System' started by swoy45, Oct 3, 2021.

  1. swoy45

    swoy45

    Joined:
    Feb 1, 2018
    Posts:
    9
    Hello!Code

    There is problem with method GetBindingIndex. Either I don't really understand how it should work or it doesn't work as expected. Basically, it should work similar to IndexOf(element) of List<T> and return you correct result at least when you passing unmodified element directly obtained through foreach. GetBindingIndex does it with variable success.

    For instance, I have a several actions, some of which are simple button type and some are composite vector2.
    upload_2021-10-3_2-31-34.png
    Even when i'm trying to do very basic cycle to obtain binding index of every element, I'm not getting expected result.
    Code (CSharp):
    1. foreach (InputBinding binding in action.action.bindings)
    2. {
    3.       Debug.Log($"{action.action.name}, path: {binding.effectivePath}, Index: {action.action.GetBindingIndex(binding)}");
    4. }
    upload_2021-10-3_2-36-33.png
    As you can see, this method returns correct index only for composite bindings so it doesn't work properly. I can do another method override with GetBindingIndex(string group, string path) but due to ingame rebinding system which working with different paths every time I can't rely on it. Also, I can't just put an int inside loop to make it count iterations because there is a case where I should go through an Action Map bindings array, so the loop iterations would be different from action's actual binding indexes.
     
  2. rubendariohh

    rubendariohh

    Joined:
    Oct 14, 2017
    Posts:
    32
    Hi, did you found a way to get the correct Binding Index for Non Composite Bindings?
    I always get -1