Hey there - I’m trying to develop a settings menu with rebindable controls, but I’m having an issue with saving the actionmap / actionasset. The controls work in the scene that I’m rebinding the controls in, but as I’m calling ToJson, I’m not getting the updated overrides in the outputted json file. I tried calling ToJson on the inputActionAsset, on action.actionMap, and on operation.action.actionMap, but nothing seems to be working. How can I save these controls? Thanks in advance.
public InputActionAsset inputActionAsset;
void RebindCompleted(Button button, InputAction action, InputActionRebindingExtensions.RebindingOperation operation, int bindingNum) {
rebindingCover.SetActive(false);
action.Enable();
operation.Dispose();
button.transform.GetChild(0).GetComponent<Text>().text = InputControlPath.ToHumanReadableString(operation.action.bindings[bindingNum].overridePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
action = operation.action;
string inputAction = action.actionMap.ToJson();
string destination = Application.persistentDataPath + "/input.json";
File.WriteAllText( destination , inputAction );
}
void SetInput(Button button, InputAction action, int bindingNum) {
rebindingCover.SetActive(true);
action.Disable();
var rebindOperation = action.PerformInteractiveRebinding(bindingNum).WithControlsExcluding("<Mouse>/position").WithControlsExcluding("<Mouse>/delta").OnMatchWaitForAnother(0.1f).OnComplete(operation => RebindCompleted(button, action, operation, bindingNum)).Start();
}
void CreateInputActionBinding(string name, InputAction action, int bindingNum) {
RectTransform t = Instantiate(buttonOptionTemplate, category) as RectTransform;
t.anchoredPosition = new Vector2(t.anchoredPosition.x, -ypos);
t.GetChild(0).GetComponent<Text>().text = name;
Button button = t.GetChild(1).GetComponent<Button>();
button.onClick.AddListener(delegate {SetInput(button, action, bindingNum);});
Text buttonText = t.GetChild(1).GetChild(0).GetComponent<Text>();
buttonText.text = InputControlPath.ToHumanReadableString(action.bindings[bindingNum].effectivePath, InputControlPath.HumanReadableStringOptions.OmitDevice);
}
CreateInputActionBinding("Sprint", inputActionMap.FindAction("Sprint", true), 0);