Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Help] Input system assert when saving rebinds

Discussion in 'Input System' started by Deleted User, Oct 12, 2021.

  1. Deleted User

    Deleted User

    Guest

    So I'm using the following code to load input actions on Start and save whenever a binding is rebound. I am using the code from this previous post: https://forum.unity.com/threads/how-to-save-input-action-bindings.799311/. But whenever I rebind a key and SaveKeybinds gets called called I get the following exception

    upload_2021-10-12_11-14-11.png

    This is also accompanied by failing to load keybinds on start. Heres the code I use:

    Code (CSharp):
    1.     [SerializeField] InputActionAsset inputAsset;
    2.     [SerializeField] List<RebindActionUI> rebindUis;
    3.  
    4.     void Start()
    5.     {
    6.         LoadKeybinds();
    7.  
    8.         foreach (var rebind in rebindUis)
    9.             rebind.stopRebindEvent.AddListener(SaveKeybinds);
    10.     }
    11.  
    12.     void SaveKeybinds(RebindActionUI ui, InputActionRebindingExtensions.RebindingOperation opr)
    13.     {
    14.         var rebinds = inputAsset.ToJson();
    15.         PlayerPrefs.SetString("Rebinds", rebinds);
    16.     }
    17.  
    18.     void LoadKeybinds()
    19.     {
    20.         var rebinds = PlayerPrefs.GetString("Rebinds");
    21.  
    22.         if (!string.IsNullOrEmpty(rebinds))
    23.             inputAsset.LoadFromJson(rebinds);
    24.     }
    Is this an issue with my setup or is it a Unity issue? Thanks.