Hello everyone.
So I’ve noticed that it is possible to create actions using the script, but I have not found a way of saving and preserving them.
I know that I can save changed Bindings using “SaveBindingOverridesAsJson()” but so far I have not found a way of saving the actions and assigned bindings I’ve created during runtime.
I know that I can make Maps and Assets to and from Json, but if I do so, I seem to be unable to use them with the Auto Generated C# Class and Input System I’ve created.
So when I try to use the (Input System's generated C# Class object).asset.LoadFromJson(myFile)
function, then I get the following error when enabling the ActionMap:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.InputSystem.InputActionMap.ResolveBindings () (at Library/PackageCache/com.unity.inputsystem@1.1.0-preview.3/InputSystem/Actions/InputActionMap.cs:1146)
UnityEngine.InputSystem.InputActionMap.ResolveBindingsIfNecessary () (at Library/PackageCache/com.unity.inputsystem@1.1.0-preview.3/InputSystem/Actions/InputActionMap.cs:1026)
UnityEngine.InputSystem.InputActionMap.Enable () (at Library/PackageCache/com.unity.inputsystem@1.1.0-preview.3/InputSystem/Actions/InputActionMap.cs:546)
InputControler+InGameScreenActions.Enable () (at Assets/InputControler.cs:287)
Assets.InputHandler.OnEnable () (at Assets/InputHandler.cs:40)
Okay, so on my way of finding a solution I tried to abandon the generated Input System Class, and just use a created Action map for what I need. This seems to somewhat work, but I feel like I’m encountering a strange bug. It seems like that myActionMap.FindAction(skillName).bindings[0]
and _skillMap.ToJson()
have different values stored for the bindings after the remapping. The following code is part of the function that gets called in .OnComplete(...)
Debug.Log("Actual Binding for " + skillName + ": " + _skillMap.FindAction(skillName).bindings[0]);
Debug.Log("Amount of Bindings for " + skillName + ": " + _skillMap.FindAction(skillName).bindings.Count);
Debug.Log("Action Map that contains " + skillName + ": " + _skillMap.ToJson());
The output unity gives me is the following:
Actual Binding for Force of Fire: Force of Fire:<Keyboard>/b
Amount of Bindings for Force of Fire: 1
{
"maps": [
{
"name": "Skill Map",
"id": "...",
"actions": [
...,
{
"name": "Force of Fire",
"type": "Value",
"id": "88dc203e-9346-4015-af53-48406102af70",
"expectedControlType": "",
"processors": "",
"interactions": ""
},
...
],
"bindings": [
...,
{
"name": "",
"id": "709796b4-c10b-4e04-a2df-5dd1f8c44fe8",
"path": "<Keyboard>/k",
"interactions": "",
"processors": "",
"groups": "",
"action": "Force of Fire",
"isComposite": false,
"isPartOfComposite": false
},
...
]
}
]
}
(I’ve replaced part’s that should be unimportant with “…”)
Is this supposed to behave that way? And if so, what am I doing wrong/what should I change?