I am creating temporary InputBindings during runtime and facing an issue related to domain reload. Everything works as expected when I launch the game: I create a new input binding, use it, and erase it when I don’t need it anymore. However, when I reenter playmode without a domain reload for a second time and enable any InputAction, I get multiple error messages, starting with a failed assertion stating “Action map must be contained in state.” This issue occurred in Unity 2023.2.20 and I was able to recreate it in Unity 6000.0.2 as well.
To give some context on what I am trying to achieve: My goal is to use temporarily created empty Input Bindings during runtime that players can override to create secondary custom bindings for an action. A typical example would be players who bind their jump to both the spacebar and the mouse wheel. This setup works for me, and I can create and save these secondary input bindings in a build. However, in the editor, my inputs break every second time I enter playmode without a domain reload.
This is the code and setup I use to recreate the issue ind Unity 6000.0.2 using version 1.8.2 of the Input System package.
using System;
using UnityEngine;
using UnityEngine.InputSystem;
public class InputBindingSystem : MonoBehaviour
{
[SerializeField] private InputActionReference uiClickInputReference;
[SerializeField] private InputActionReference jumpInputReference;
// GUID to access and identify the InputBinding with.
private readonly Guid _bindingId = new("00a8aeb6-a075-4134-a16a-8573464c0cc8");
private void Awake()
{
// UI Click is located in a different Input Action Map than Jump
uiClickInputReference.action.performed += OnUIClickPerformed;
// This is where the error occurs when entering Playmode for a second time.
uiClickInputReference.action.Enable();
Debug.Log($"InputBindingSystem: Creating new temporary InputBinding with id {_bindingId}");
jumpInputReference.action.performed += OnJumpPerformed;
var action = jumpInputReference.action;
action.Disable();
var binding = new InputBinding
{
id = _bindingId,
path = "<Keyboard>/leftAlt"
};
jumpInputReference.action.AddBinding(binding);
action.Enable();
}
private void OnDestroy()
{
jumpInputReference.action.performed -= OnJumpPerformed;
uiClickInputReference.action.performed -= OnUIClickPerformed;
Debug.Log($"InputBindingSystem: Erasing temporary InputBinding with id {_bindingId}");
var action = jumpInputReference.action;
action.Disable();
action.ChangeBindingWithId(_bindingId.ToString()).Erase();
}
private void OnJumpPerformed(InputAction.CallbackContext context)
{
Debug.Log($"Jump Performed With {context.control.path}");
}
private void OnUIClickPerformed(InputAction.CallbackContext context)
{
Debug.Log($"Click Performed With {context.control.path}");
}
}
This is my scene setup and my console output when I enter playmode for the first time.
Is this an internal issue or bug inside the Input System, or am I doing something wrong? I tried multiple things, like disposing of the InputActions during shutdown, and searched for others with similar issues but have had no success so far.