Hi!
I use this code to save my control overrides :
public static void SaveControls(InputActionAsset controlsAsset)
{
InputControlsProfile inputControlsProfile = ScriptableObject.CreateInstance<InputControlsProfile>();
foreach (InputActionMap actionMap in controlsAsset.actionMaps)
{
foreach (InputBinding inputBinding in actionMap.bindings)
{
if (!string.IsNullOrEmpty(inputBinding.overridePath))
{
inputControlsProfile.Bindings.Add(new InputBindingProfile(inputBinding.id.ToString(),
inputBinding.overridePath));
}
}
}
ProfileSaveSystem.SaveUnique(inputControlsProfile);
}
And this code to load it :
public static PlayerControls LoadPlayerControls()
{
PlayerControls playerControls = new PlayerControls();
ClearBindingOverrides(playerControls.asset);
if (ProfileSaveSystem.ContainsSavedElement<InputControlsProfile>())
{
InputControlsProfile inputControls = ProfileSaveSystem.LoadUnique<InputControlsProfile>(
ProfileSaveSystem.SaveFolderPath +
$"{nameof(InputControlsProfile)}{ProfileSaveSystem.FileExtension}");
;
Dictionary<System.Guid, string> overrides = new Dictionary<System.Guid, string>();
foreach (InputBindingProfile inputBindingProfile in inputControls.Bindings)
{
Debug.Log($"adding override {inputBindingProfile.Path}");
overrides.Add(new System.Guid(inputBindingProfile.ID), inputBindingProfile.Path);
}
foreach (InputActionMap actionMap in playerControls.asset.actionMaps)
{
var bindings = actionMap.bindings;
for (int i = 0; i < bindings.Count; ++i)
{
if (overrides.TryGetValue(bindings[i].id, out string overridePath))
{
Debug.Log($"applying override {overridePath} to {actionMap.name} {bindings[i].name}");
actionMap.ApplyBindingOverride(i, new InputBinding {path = overridePath});
}
}
}
}
else
{
Debug.Log($"load failed");
}
return playerControls;
}
My button calls the refresh function on Awake() :
[...]
playerControls = PlayerControlsUtilities.LoadPlayerControls();
UpdateText();
[...]
And when I log on the update :
Debug.Log($"{actionReference.action.bindings[GetBindingIndex()].effectivePath} {actionReference.name} {actionReference.action.bindings[GetBindingIndex()].name} override?null:{string.IsNullOrEmpty(actionReference.action.bindings[GetBindingIndex()].overridePath)}");
I get this result :
<Keyboard>/w Player/Move up override?null:True
UnityEngine.Debug:Log(Object)
Menus.MainMenus.OptionsMenu.Controls.KeyBindingCompositeProfile:FixedUpdate() (at Assets/Scripts/Menus/MainMenus/OptionsMenu/Controls/KeyBindingCompositeProfile.cs:22)
Can you tell me what is happening here? The overrides should be applied, right?