Runtime InputSystem Issue 'Action Map Must Be Contained in State' on Playmode Reentry

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.

9846750--1417233--upload_2024-5-21_12-34-48.png

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.
9846750--1417260--upload_2024-5-21_12-45-26.png
9846750--1417263--upload_2024-5-21_12-46-21.png

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.

It helped me to remove “action.Enable()”; This error also appeared.
or

if (!action.enabled)
        {
            action.Enable();
        }

I’m already avoiding the action.Enable() call in the project where the issue originally occurred. The problem is that the EventSystem is enabling some actions that aren’t even from the same action map as the ones I modified (likely actions from the standard UI action map). This means I can’t completely avoid the action.Enable() call. While this might work for some, it doesn’t for me. My temporary solution is to avoid creating secondary runtime input bindings in the editor and only enable them in a build. I’ve also filed a bug report and will update this thread once I have more information.

Edit: The issue was confirmed to be a bug by Unity. Here is the link to the Issue Tracker

The issue was fixed in 1.9.0