I'm making control settings menu to let player change settings. My controls made using new unity input system. I've already made script to rebind simple binds like jump or using skills. But my movements binded as composite Vector2 bind. Here is rebinding script that I put on every rebind button:
using UnityEngine;
using UnityEngine.InputSystem;
using TMPro;
using UnityEngine.EventSystems;
public class RebindButton : MonoBehaviour
{
[SerializeField] private InputActionReference inputActionRef;
[SerializeField] private TMP_Text buttonText;
private InputActionRebindingExtensions.RebindingOperation rebindingOperation;
private void Start()
{
int bindingIndex = inputActionRef.action.GetBindingIndexForControl(inputActionRef.action.controls[0]);
buttonText.text = InputControlPath.ToHumanReadableString(inputActionRef.action.bindings[bindingIndex].effectivePath,
InputControlPath.HumanReadableStringOptions.OmitDevice);
}
public void StartRebinding()
{
rebindingOperation = inputActionRef.action.PerformInteractiveRebinding()
.WithCancelingThrough("<Keyboard>/escape")
.WithControlsExcluding("Mouse")
.OnMatchWaitForAnother(0.1f)
.OnCancel(operation => FindObjectOfType<EventSystem>().SetSelectedGameObject(null))
.OnComplete(operation => RebindComplete())
.Start();
}
private void RebindComplete()
{
int bindingIndex = inputActionRef.action.GetBindingIndexForControl(inputActionRef.action.controls[0]);
buttonText.text = InputControlPath.ToHumanReadableString(inputActionRef.action.bindings[bindingIndex].effectivePath,
InputControlPath.HumanReadableStringOptions.OmitDevice);
rebindingOperation.Dispose();
FindObjectOfType<EventSystem>().SetSelectedGameObject(null);
}
}
Input system looks something like this:

What should I use to be able to rebind my movements. Now I can't do it because I can't choose MoveUp action as input action reference. The only thing I can choose is whole movement. I understand that key of my problem is binding index variable, but I don't have an idea how to make this code work for composite bindings and for simple bindings at the same time.
I've tried to use .withTargetBinding but didn't really understand how to get neccessary ID for it.
Unity have good sample illustrating exactly this case with Vector2 binding.
In your movement composite, index 0 is Composite Binding itself, 1 is "Up: W", 2 is "Down: S" etc.
To work with Composite Bindings and regular ones, you can check for .isComposite flag on binding. Then use 0 index for non composites and >0 for composites.
There is short example of rebind UI