How to effectively obtain Binding Index?

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 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.

Even when i’m trying to do very basic cycle to obtain binding index of every element, I’m not getting expected result.

foreach (InputBinding binding in action.action.bindings)
{
      Debug.Log($"{action.action.name}, path: {binding.effectivePath}, Index: {action.action.GetBindingIndex(binding)}");
}

7541737--931657--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.

Hi, did you found a way to get the correct Binding Index for Non Composite Bindings?
I always get -1

1 Like

I also have the same question, has anyone found out how to get the “binding index”?

I always have it -1

1 Like

Probably a bit late, but I didn’t find an answer elsewhere.
This is what I used:

_controls = new Controls();
var debug = "";
foreach (var map in _controls.asset.actionMaps){
    debug += map.name + "\n";
    foreach (var action in map.actions){
        debug += "\t" + action.name + "\n";
        foreach (var binding in action.bindings){
            debug += "\t \t" + binding.path + "\t" + action.GetBindingIndex(binding) + "\n";
        }
    }
}
print(debug);

Then copy the output text to a spreadsheet to reference.