Search Unity

Bug Storing InputAction action as a Variable, Save Load Binding Overrides not working ?

Discussion in 'Input System' started by edin97, May 1, 2023.

  1. edin97

    edin97

    Joined:
    Aug 9, 2021
    Posts:
    58
    I made a rebinding system, modifying the RebindActionUI script. it works great. Until I decide to, in a random script, do this :
    Code (CSharp):
    1.  
    2.     private void Awake()
    3.     {
    4.         InputAction inputAction = playerInput.actions[actionName];
    5.     }
    This line of code stops any rebinding from happening while the game is running... if the game restarts, it still doesn't load the correct rebindings.

    This is what I do after I finish rebinding the keys (after swapping if they already exist) :
    Code (CSharp):
    1.  
    2.     public InputActionAsset InputActions;
    3. (...)
    4.     private void OnKeybindRebind(string actionName, string actionPath)
    5.     {
    6.         var rebinds = InputActions.SaveBindingOverridesAsJson();
    7.         PlayerPrefs.SetString("rebinds", rebinds);
    8.         (...)
    9.         rebinds = PlayerPrefs.GetString("rebinds");
    10.         InputActions.LoadBindingOverridesFromJson(rebinds);
    11.     }
    This is basically it, I tested and it's exactly when adding this line that it stops all rebinding from working.

    I tested NOT storing "playerInput.actions[actionName];" in a variable. It works. So for now I'm simply not storing it, but I think it breaks the bindingoverrides somehow idk.

    I writting this just in case a dev sees it as a potential bug, bc I'm quite confident a variable shouldn't make saving or loading rebinds break

    I'm using 1.3.0 I think and unity 2020.3.15f2.