Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Rebinding Inputs not working or saving

Discussion in 'Input System' started by pantang, Jun 21, 2020.

  1. pantang

    pantang

    Joined:
    Sep 1, 2016
    Posts:
    219
    I am trying to load some custom keybindings for the new input manager, I have first saved them with this code but sadly this only saves the original asset and not the new keybindngs created with RebindActionUI script, my UI components seem to be working correctly and the display updates fine and keeps the new values but it does not change anything in my asset and the new bindings aren't set active/overridden in the player either.

    Code (CSharp):
    1.         if (File.Exists(playerData.bindingPath))
    2.             File.Delete(playerData.bindingPath);
    3.         if (!File.Exists(playerData.bindingPath))
    4.         {
    5.             // Create a file to write to.
    6.             File.WriteAllText(playerData.bindingPath,playerData.controls.asset.ToJson(), Encoding.UTF8);
    7.         }
    Then when I try to load the data back up I loose my controls all together and the actions maps can't be referenced, this is complete guess work on my behalf so I presume I have got a lot wrong, I use the following to load my json which doesn't kick up any errors, just does lose my maps.



    Code (CSharp):
    1.         if (File.Exists(bindingPath))
    2.         {
    3.             string loadBindings = File.ReadAllText(bindingPath);
    4.             //Debug.Log(loadBindings);
    5.             //controls.Dispose();
    6.             controls.asset.LoadFromJson(loadBindings);
    7.         }

    New Controls is the input asset and PlayerData error is when I try and enable one of the actionmaps after loading the saved json data.

    NullReferenceException: Object reference not set to an instance of an object
    UnityEngine.InputSystem.InputActionMap.ResolveBindings () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Actions/InputActionMap.cs:1126)
    UnityEngine.InputSystem.InputActionMap.ResolveBindingsIfNecessary () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Actions/InputActionMap.cs:1016)
    UnityEngine.InputSystem.InputActionMap.Enable () (at Library/PackageCache/com.unity.inputsystem@1.0.0/InputSystem/Actions/InputActionMap.cs:544)
    NewControls+PlayerActions.Enable () (at Assets/New Controls.cs:1248)
    PlayerData.Start () (at Assets/Scripts/Player/PlayerData.cs:174)


    Any help would be much appreciated, and even with this little headache, new system is so much better, thank you Mr Unity man.
     
    Last edited: Jun 22, 2020
    Korov and d633X3A7xcGerFY like this.
  2. Korov

    Korov

    Joined:
    Apr 17, 2017
    Posts:
    3
    Hello Unity, any words for this topic?
    We can't save rebinded keys, any fix soon?
     
  3. pantang

    pantang

    Joined:
    Sep 1, 2016
    Posts:
    219
    Yes please I love the new input system, its an absolute joy to work with but I still havent figured out how to get the rebindUI elements to actually affect my controls. On top of my todo list that i keep avoiding.