Quick answer: Something created a GameObject while the scene was being unloaded, almost always from OnDestroy or OnDisable: a death effect, a dropped item, or a lazy singleton recreating itself. Skip spawning when gameObject.scene.isLoaded is false or the application is quitting, and make singletons refuse to recreate during shutdown.
You stop Play mode or load another scene and the Console lists leftover objects. It is a warning, not an error, but those leaked objects survive into edit mode or the next scene, and in builds they can carry stale state across scene loads.
The exact warning
Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)
The following scene GameObjects were found:
Explosion(Clone)
AudioManager
The names listed are your leads: they are the objects created during teardown.
Why it happens
When a scene unloads or Play mode stops, Unity destroys every object in it, calling OnDisable and OnDestroy on each. Gameplay code that reacts to destruction (spawn an explosion when an enemy dies, drop loot, play a sound through a manager) cannot tell the difference between “this enemy was killed” and “the whole scene is going away”, so it spawns new objects into a scene that is being torn down.
Fix 1: do not spawn during teardown
static bool quitting;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void ResetQuitFlag()
{
quitting = false;
Application.quitting += () => quitting = true;
}
void OnDestroy()
{
// The scene is unloading or the game is quitting: not a death.
if (quitting || !gameObject.scene.isLoaded) return;
Instantiate(explosionPrefab, transform.position, Quaternion.identity);
}
gameObject.scene.isLoaded is false while the scene is unloading, which catches scene changes; the quit flag catches application exit and leaving Play mode. Resetting the flag on load keeps it correct when domain reload is disabled.
Better: spawn effects where the death happens
Instead of spawning from OnDestroy, spawn from the method that kills the object, then destroy it. OnDestroy then only cleans up. This removes the ambiguity entirely and makes the gameplay code easier to follow:
public void Die()
{
Instantiate(explosionPrefab, transform.position, Quaternion.identity);
Destroy(gameObject);
}
Fix 2: singletons that recreate themselves
A lazy singleton that creates a new GameObject whenever Instance is null is the other common source. During teardown the manager is destroyed first, then another object's OnDestroy calls AudioManager.Instance.Play(...), and a fresh manager is created in the dying scene.
public static AudioManager Instance
{
get
{
if (instance == null && !quitting)
instance = new GameObject("AudioManager").AddComponent<AudioManager>();
return instance; // may be null during shutdown: callers use ?.
}
}
Callers in OnDestroy and OnDisable should use AudioManager.Instance?.Play(...), or better, not reach for managers during teardown at all.
Other sources
OnDisablespawning or reparenting objects (runs during teardown too).- Coroutines or async callbacks that complete after the scene started unloading.
DontDestroyOnLoadobjects created by a script in a scene that is closing.
Leaks that cross scenes in builds
In a build, a leaked manager or effect carries old state into the next scene, which is how “second run through the level is broken” bugs start. Bugnet's Unity SDK hooks Unity's log stream, so exceptions and errors in a player's build are filed automatically with the last log lines, a screenshot, the device, OS and build version, and identical ones stack into a single issue with a count.
Related problems
- Fix: Unity Scene Reload Leaves DontDestroyOnLoad Duplicates
- How to Fix a Singleton Holding State Across Tests
- How to Fix Tests Leaking DontDestroyOnLoad Objects Across Play-Mode Tests
Frequently asked questions
What does “Some objects were not cleaned up when closing the scene” mean?
A script created GameObjects while the scene was being destroyed, usually from OnDestroy or OnDisable, so they were left behind after the scene closed.
How do I stop spawning objects in OnDestroy when the scene unloads?
Return early from OnDestroy when gameObject.scene.isLoaded is false or the application is quitting, or move the spawn into the method that kills the object.
Why does my singleton cause this warning?
Its Instance getter creates a new GameObject when called during teardown. Do not create new instances while quitting or unloading, and use null-conditional calls from OnDestroy.
OnDestroy cannot tell a death from a scene unload. Spawn effects where the death happens.