# Unloading Scenes

## General

Unloading scenes is the same as loading scenes, except to call Unload rather than Load. Scenes can be unloaded by connection, or globally. When unloaded globally scenes will be unloaded for all players. When unloading by connection only the connections specified will unload the scenes.

## Unloading scenes

### Global scenes

* **Global Scenes** can be unloaded by calling UnloadGlobalScenes() in the SceneManager.
* You cannot unload a global scene with UnloadConnectionScenes() method.

```csharp
SceneUnloadData sud = new SceneUnloadData("Town");
base.NetworkManager.SceneManager.UnloadGlobalScenes(sud);
```

### Connection scenes

**Connection Scenes** follow the same principle, but has a few method overloads. You can unload scenes for a single connection, multiple connections at once, or unload scenes on the server.

* The Server will only Unload a connection scene on itself, if all connections have been unloaded from that scene.
* If you wish to unload a scene and all connections, get all the connections in the scene and call unload with those connections. SceneManager.SceneConnections holds all online scenes and the connections in them.
* If you wish to keep a scene loaded on server when unloading all Connections See [**Scene Caching**](/docs/guides/features/scene-management/scene-caching.md).

```csharp
SceneUnloadData sud = new SceneUnloadData(new string[] { "Main", "Additive") });

// Unload scenes for a single connection.
NetworkConnection conn = base.Owner;
base.NetworkManager.SceneManager.UnloadConnectionScenes(conn, sud);

// Unload scenes for several connections at once.
NetworkConnection[] conns = new NetworkConnection[] { connA, connB };
base.NetworkManager.SceneManager.UnloadConnectionScenes(conns, sud);

// Unload scenes only on the server.
// that you don't want all players in.
base.NetworkManager.SceneManager.UnloadConnectionScenes(sud);
```

## Advanced info

### Behind the "scenes"

The [**SceneManager**](/docs/fishnet-building-blocks/components/managers/scenemanager.md) Class has very detailed XML comments on how the unload process works in detail, if you need to troubleshoot the scene unload process, these comments will help you understand the flow of how a scene loads.

### Events

Make sure to check out the [**Scene Events**](/docs/guides/features/scene-management/scene-events.md) that you can subscribe to to give better control over your game.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fish-networking.gitbook.io/docs/guides/features/scene-management/unloading-scenes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
