Ok so for those of you looking for an answer out there, here’s the solution I came up with. I hope it saves you a headache and some research time.
If you want to rebind multiple axis bindings this is how you do it:
I discovered that everything under the axis action is considered a binding including the sub axis’s (in my case 1DAxis and 1DXAxisController as see in my comment above) so the order would go as follows:
0 1DXAxis
1 Negative: S [Keyboard]
2 Positive: W [Keyboard]
3 1DXAxisController
4 Negative: Left Stick/Down [Gamepad]
5 Positive: Left Stick/Up [Gamepad]
so the keyboard keys can be assigned as follows using the indexes 1 and 2:
//rebind vertical keyboard
inputAction.PlayerControls.Vertical.ApplyBindingOverride(1, k[1]);
inputAction.PlayerControls.Vertical.ApplyBindingOverride(2, k[0]);
//rebind horizontal keyboard
inputAction.PlayerControls.Horizontal.ApplyBindingOverride(1, k[2]);
inputAction.PlayerControls.Horizontal.ApplyBindingOverride(2, k[3]);
The k[ ] array being the keybind such as: /a
and for the controller, as follows using the indexes 4 and 5:
//rebind vertical controller
inputAction.PlayerControls.Vertical.ApplyBindingOverride(4, c[1]);
inputAction.PlayerControls.Vertical.ApplyBindingOverride(5, c[0]);
//rebind horizontal controller
inputAction.PlayerControls.Horizontal.ApplyBindingOverride(4, c[2]);
inputAction.PlayerControls.Horizontal.ApplyBindingOverride(5, c[3]);
The c[ ] array being the keybind such as: /eastButton
As for the second problem, what i did is just us the actionToRebind.PerformInteractiveRebinding() method to rebind an empty action called temp which isn’t ever used by the player and tell it within the rebind operation to pull the key string and assign it to another string also called temp:
public void ListenForKey(int ci)
{
inputAction.Disable();
//Debug.Log($"'{inputAction.PlayerControls.Temp}'");
RemapButtonClicked(inputAction.PlayerControls.Temp);
inputAction.Enable();
}
public void RemapButtonClicked(InputAction actionToRebind)
{
var rebindOperation = actionToRebind.PerformInteractiveRebinding(0)
.WithControlsExcluding("<Keyboard>/escape") //to prevent the player from re binding the pause key
.WithControlsExcluding("<Gamepad>/select") //to prevent the player from re binding the pause key
.WithControlsExcluding("<Pointer>/position") // Don't bind to mouse position
.WithControlsExcluding("<Pointer>/delta"); // Don't bind to mouse movement deltas
rebindOperation.OnComplete(
operation =>
{
//Debug.Log($"Rebound '{actionToRebind}' to '{operation.selectedControl}'");
temp = $"'{operation.selectedControl}'";
temp = FormatKeyCode(temp);
operation.Dispose();
});
rebindOperation.Start();
}
the string will end up looking something like this: Key:/Keyboard/a
So I also wrote the FormatKeyCode() method to change the string to this format: /a which is the format used by the .ApplyBindingOverride() method, I doubt I’ve done it in the most efficient way but here it is anyway if you’re interested:
public string FormatKeyCode(string t)
{
int i = 0;
string x = "";
while(i < t.Length)
{
if(t[i] == ':')
{
x += "<";
break;
}
i++;
}
i++;
i++;
while(i < t.Length)
{
if(t[i] == '/')
{
x += ">/";
break;
}
x += t[i];
i++;
}
i++;
while(i < t.Length)
{
string j = "'";
if(t[i] == j[0])
{
break;
}
x += t[i];
i++;
}
return x;
}
I then took the temp string, assigned to an array, and then bound it in another script when I needed to.
I hope this helps someone out there. If you have any questions let me know.