Performance Issues and Input Callbacks with New Unity Input System

Message:

Hi,

I’m encountering a persistent issue in my Unity project related to the new Input System.

I am on Unity 2022.3.7f1 with Input System 1.6.3

In my platformer game project, we’ve adopted the new Unity Input System for handling player input. However, as the game progresses and scenes are reloaded frequently due to player retries, we’ve noticed a degradation in performance and unexpected behavior. After around 100 scene reloads, the game becomes increasingly buggy, and there are noticeable spikes in input response times.

Profiler :

I’ve used Unity’s Profiler to investigate the issue further, and I’ve identified that the performance degradation is occurring in the “PreUpdate.NewInputUpdate” section, specifically in the chain “NativeInputSystem.NotifyUpdate() → InputUpdate → InputActionCallback”. This leads me to believe that there might be some inefficiency or incorrect handling in our input callbacks. Moreover, the issue happens only when reloading / loading a scene !

Input Handling Code:

Here’s a portion of the input handling code that I suspect might be contributing to the issue:

    private void SetupControls()
    {
        controls.Player.Jump.performed += ctx => OnActionTriggered();
        controls.Player.Power.performed += ctx => OnActionTriggered();
        controls.Player.Move.started += ctx => OnActionTriggered();

        controls.Player.Jump.performed += ctx => OnJump();

        controls.Player.Move.started += ctx => OnMove(ctx);
        controls.Player.Move.canceled += ctx => OnMove(ctx);

        // Other enabling...
    
    }

public void OnEnable()
{
    if (controls == null)
        controls = new PlayerControls();

    InputManager.SyncWithBindingOverrides(controls);

    SetupControls();
    controls.Enable();
}

public void OnDisable()
{
    controls.Player.Disable();
}

Are there any best practices I should be following when setting up and managing input callbacks? Is there a way to ensure proper subscription and unsubscription of callbacks to prevent accumulation and potential memory leaks?

I do not frequently do forum posts so it might lacks information or clarity, please do not hesitate if you need any further information.

Thank you in advance for your time and assistance!

Best regards,

Arthur

Hi @Nours10 - seeing a similar issue in #Unity-2022-3-LTS (2022.3.20f1) with the Input-System. After several restarts (Reloading main scene), the application slows down. The profiler is spending about 57ms in NativeInputSystem.NotifyUpdate()InputUpdateInputActionCallback, similar to what you’ve found.

Did you end up getting any workarounds for this?

Sorry for necroing an old post but this is active when I don’t even use the event systems. I just use the Pointer.current.position.ReadValue() once every frame somewhere, and I’m paying 4.57ms for it every frame?

  • more information: I’m using Release mode and setting Unity.exe to “efficient mode” from Task Manager to test performance critical code paths, and the whole PlayerLoop is 21.47ms, so the input system is taking 20% of each frame!