[BUG] Unity 6 Build Game Process Continues Running in Background After Closing Window

After upgrading to unity 6. When I try to close my multiplayer game, the process continues running in the background even after closing the window.

Specifically:

  • When I press Alt + F4 or click the close button, only the game window closes
  • The game process remains active in the background
  • This happens immediately after launching the game
  • The issue occurs even before connecting to the Network Manager or loading the main menu
  • I can verify this by checking Task Manager, where the process is still running

Technical Details:

  • Unity Version: 6000.0.32
  • Build Type: Mono
  • Network Solution: NGO
  • NGO Version: 2.1.1

Steps to Reproduce:

  1. Launch the game
  2. Attempt to close it using Alt + F4 or the window close button
  3. Check Task Manager to confirm the process is still running

Has anyone encountered this issue or knows how to properly terminate the game process when closing the window?

9 Likes

This should not happen. I suspect this has something to do with the project rather than being a general issue. Try to strip down a copy of the project to the bare minimum that exhibits this behavior.

I would start with leaving only an empty scene in the build scene list. If this shuts down properly you know it‘s a project specific issue. Otherwise it may be a bug, a project setting (or several), an installed package or asset that still makes it into the build somehow, or less likely a system issue (eg drivers).

1 Like

Hi, I also have this bug on Unity 6000 - (thread)

I made a minimal project that reproduces this bug - download zipped project

5 Likes

That is awesome… now please report it!

If you have a bug, there is only one way to report it.

Help → Report A Bug.

Report one bug at a time with all the expected supporting information attached.

Any other way is NOT a bug report and is NOT going to change anything.

Hello. I’m experiencing exactly the same issue. I’m using Unity 6, and it didn’t occur in previous versions. I don’t believe it’s a problem specific to individual projects.

2 Likes

I encountered the same issue. I’m using Unity version 6000.0.32f1. I have two different game projects: one is singleplayer, and the other is a multiplayer game using custom TCP/UDP communication. I tested both projects with an empty scene and a normal scene, but even after closing the game, the process continues running in the background. I also tried switching between IL2CPP and Mono for builds, but none of them solved the issue.

1 Like

I’m also experiencing the same issue in Unity 6000.0.32f1 where my game leaves multiple background processes running after closing. Initially, I thought it was related to the NetworkManager (Netcode) or Steam API, but after testing, I confirmed it’s not caused by them.

What’s strange is that these background processes keep stacking up. I noticed this when my computer started slowing down, and when I checked the Task Manager, there were around 20 background processes for my game, each using about 150 MB of RAM.

Additionally, I noticed a difference based on the scene loading status:
If I close the game after the scene loads, each background process uses ~150 MB of RAM.
If I close the game before the scene loads, each process only uses ~60 MB of RAM.

4 Likes

I just noticed that as well, Unity 6. Just upgrade to the latest version (33f1) and it happens even with a brand new project. Mine was the HDRP base template. Nothing added, just build this, run the game, close, and the process will stick in the windows process list, and never kill itself.

It piles up if we run the game again and again.

3 Likes

I have this issue, too. Has anyone filed a bug already that we all can vote on?

1 Like

Hello

I’ve been waiting for Unity support, but it didn’t work, so I found this solution which works for me. Put the script below in a GameObject that exists in every scene:

using UnityEngine;

public class ApplicationQuitHandler : MonoBehaviour
{
    void OnApplicationQuit()
    {
        if (!Application.isEditor)
        {
            System.Diagnostics.Process.GetCurrentProcess().Kill();
        }
    }
}
9 Likes

Same here. Worked for me, thnx a lot :slight_smile:

Unity 6.0.30

Same bug with Input System any version: 1.10 1.11.2 1.12

Removing Input System fixes bug

Issue still.

Unity 6
6000.0.29f1c1.7976.5667
Revision: 6000.0/china_unity/29f1 a1dcd17d2779
Built: Thu, 28 Nov 2024 20:18:53 GMT

System.Diagnostics.Process.GetCurrentProcess().Kill(); can’t be used with IL2CPP. But looks like it can be replaced with Environment.FailFast(string.Empty);.

3 Likes

@vlklubkov
Thanks for the tip for IL2CPP builds! Just a note for others: Environment.FailFast() requires user input after the process terminates. Windows 10 reacts as if the app is frozen. Depending on the use case, this may not be acceptable.

@rockin
Here is also a link to the bug tracker: Unity Issue Tracker - Player .exe remains open as a background task after closing it when Active Input Handling is set to "Input System Package (New)"

2 Likes

@AM_FX That’s interesting, thanks for sharing! I only tested on Windows 11, and it doesn’t seem to need any user input, the app simply closes. The only side effect I experienced for FailFast() is that it creates crash report files for Development builds, a large one in %LOCALAPPDATA%\CrashDumps and a small one in %PROGRAMDATA%\Microsoft\Windows\WER\ReportQueue.

But I also found a different solution here:

private void OnApplicationQuit()
{
#if !UNITY_EDITOR
    [DllImport("kernel32.dll",SetLastError=true)]
    static extern int TerminateProcess(IntPtr hProcess, uint exitCode);

    var id = System.Diagnostics.Process.GetCurrentProcess().Handle;
    TerminateProcess(id, 0);
#endif
}

Despite the use of Process API, this code works fine with IL2CPP.

1 Like

Thanks! This helped.

I modified your solution a little to use RuntimeInitializeOnLoadMethod attribute instead of using a MonoBehaviour.

using System;
using System.Runtime.InteropServices;

using UnityEngine;


public static class AppTerminator
{
#if UNITY_STANDALONE_WIN && !UNITY_EDITOR
    [DllImport("kernel32.dll", SetLastError = true)]
    private static extern int TerminateProcess(IntPtr hProcess, uint exitCode);

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
    private static void InitializeOnLoad()
    {
        Application.quitting += Application_Quitting;
    }

    private static void Application_Quitting()
    {
        IntPtr handle = System.Diagnostics.Process.GetCurrentProcess().Handle;
        TerminateProcess(handle, 0);
    }
#endif
}
5 Likes

Appears to be fixed in Unity 6000.0.37f1. :partying_face:

3 Likes

Worked for me, Thank you so much :slightly_smiling_face:

Unity Version: 6000.0.32f1
Date: 26.03.2025

I don’t want to necropost, but it seems to be back in Unity 6000.2.14f1

1 Like