ActionMap.Disable() does not disable actions for all scripts

Hi,

currently I’m using the new Input System for my player controls. The actions are grouped into an actionmap, which I access via the auto-generated C# script’s namespace. In my player script, I enable and disable the actionmap - this works as expected:

private void OnEnable()
    {
        playerActionMap.Enable();
    }
    private void OnDisable()
    {
        playerActionMap.Disable();
    }

Some of the controls are also being used in other scripts. A simple example can be seen below:

public class TestOnJumpButton : MonoBehaviour
{
    private Controls controls;
    private InputActionMap playerActionMap;
  

    private void Awake()
    {
        controls = new Controls();
        playerActionMap = controls.Player;

        controls.Player.Jump.performed += ctx => TestOnInput();
    }
  
    private void OnEnable()
    {
        playerActionMap.Enable();
    }
    private void OnDisable()
    {
        playerActionMap.Disable();
    }

    private void TestOnInput()
    {
        Debug.Log("Pressed Jump Button");
   
    }

Now my problem:
I would have expected, that if I enable / disable the actionmap in one script, it would globally enable / disable it for all scripts listening to its actions. But this does not work… The “TestOnJumpButton” script only works if I enable the actionmap in this script. Also, if I disable the Player Script (and therefore the actionmap with it) during runtime, the “TestOnInput()” function is still being called whenever the Jump action is activated.

Am I overlooking something? Is this intented behaviour?

This is your clue. You’re creating a new instance for this script. If you want a global one, make ONE global instance and reference it everywhere. This is basic C# behavior and programming.

Thank you very much for your reply!
I kind of assumed it would be something like this, however I’m not expirienced enough (yet) with Unity or coding to have pinpointed it - so thanks for pointing it out!

To the solution:
I guess generally something like this could be addressed by making a singleton out of the class and attaching it to an empty gameObject (if it requires MonoBehaviour).
However - as I have the auto-created C# class of the InputSystem, including a namespace, is there a way of skipping this step? Does it include already a global static instance of my Controls() that I could access directly from different scripts somehow?