# Leave a session

> Learn how players can leave a session and what happens when they exit.

When players leave a session or get kicked out of the session, their player ID is removed from the players list. If the host leaves the session, another player in the session is randomly selected as the host. The host can also remove other players from the session. The same `RemovePlayerAsync` API call is used in both cases where the host simply specifies the other player's `playerId` instead of their own. Sessions are automatically deleted when the last player in the session leaves.

The following code sample shows how to remove a player from the lobby:

*C#*

```cs
using Unity.Services.Multiplayer;
using UnityEngine;

// ...

try
{
    // Assume 'session' is the active ISession instance the player has joined.

    // Leaving the session automatically removes the authenticated local player 
    // from the backend service and safely shuts down associated network modules.
    await session.LeaveAsync();
}
catch (SessionException e)
{
    // The Multiplayer Services SDK uses SessionException for API errors.
    Debug.Log(e);
}
```
