Search Unity

Question PlayerPrefs not loaded

Discussion in 'Input System' started by joss51, Mar 22, 2023.

  1. joss51

    joss51

    Joined:
    May 6, 2016
    Posts:
    18
    Hello,
    I added new Input System v 1.4.4
    I use the Rebinding UI sample for my customize command menu.
    Everything works fine expect one thing :
    - I use SaveBindingOverridesAsJson for saving rebinding inputs in PlayerPrefs and I see in PlayerPrefs that it's effectively saved. But when I close the build or stop/play Unity Editor, my PlayerPrefs are not loaded with LoadBindingOverridesFromJson.

    Here is my behavior script applied on the UI :

    using UnityEngine;
    using UnityEngine.InputSystem;

    public class RebindSaveLoad : MonoBehaviour

    public InputActionAsset actions;

    public void OnEnable()
    {
    var rebinds = PlayerPrefs.GetString("rebinds");
    if (!string.IsNullOrEmpty(rebinds))
    {
    actions.LoadBindingOverridesFromJson(rebinds);
    Debug.Log("rebinds exists");
    }
    else
    {
    Debug.Log("rebinds doesn't exist");
    }
    }
    public void OnDisable()
    {
    var rebinds = actions.SaveBindingOverridesAsJson();
    PlayerPrefs.SetString("rebinds", rebinds);
    Debug.Log("rebinds is saved");
    }

    Any idea ?
     
  2. joss51

    joss51

    Joined:
    May 6, 2016
    Posts:
    18
    Up !
    I have the same problem.