Skip to main content

Leaving a Session or Server

This guide explains how to disconnect a client from a multiplayer session or dedicated server in Unreal Engine using SteamCore PRO. The primary method involves using the Destroy Session node to cleanly exit a session. This is essential for ensuring proper cleanup of session data and a smooth player experience.

Prerequisites

  • SteamCore PRO installed in your Unreal Engine project.
  • A client connected to a multiplayer session or dedicated server using SteamCore PRO Sessions, SteamCoreSockets, or IpNetDriver.
  • Properly configured DefaultEngine.ini for your networking setup (see SteamCoreSockets Configuration or IpNetDriver Setup).

Using the Destroy Session Node

The Destroy Session node is used to disconnect a client from a multiplayer session or server. This node ensures that the session is properly terminated on the client side, freeing up resources and notifying the server.

Steps

  1. Add the Destroy Session Node:

    • In your client-side game logic (e.g., Game Instance, Player Controller, or Menu Blueprint), add the Destroy Session node.
    • This node is typically executed when the player chooses to leave the session (e.g., via a "Leave Game" button in the UI).
  2. Execute the Node:

    • Connect the Destroy Session node to the appropriate trigger in your game logic (e.g., a UI button press or game event).
    • The node will handle the disconnection process, cleaning up the session data and notifying the server.
  3. Handle Post-Disconnection Logic:

    • After executing the Destroy Session node, redirect the player to a main menu, lobby, or another level as needed.
    • Optionally, display a confirmation message to the player indicating they have left the session.

Example

The following Blueprint demonstrates how to leave a session using the Destroy Session node, triggered by a player action (e.g., clicking a "Leave Game" button).

Destroy Session Example

Steps in Blueprint

  1. Add a trigger event (e.g., a button press in your UI).
  2. Connect the event to the Destroy Session node.
  3. On successful execution, use the Open Level node to transition the player to a main menu or lobby level.

Notes

  • Client-Side Only: The Destroy Session node is executed on the client to disconnect from the session. It does not affect the server or other connected clients.
  • Session Cleanup: Ensure the Destroy Session node is called before transitioning to another level to avoid leaving orphaned session data.
  • Error Handling: Add logic to handle cases where the session cannot be destroyed (e.g., due to network issues) and inform the player accordingly.
  • Production Use: For a polished experience, provide clear UI feedback (e.g., a "Disconnecting..." message) while the session is being terminated.
  • SteamCoreSockets and IpNetDriver: The Destroy Session node is primarily designed for SteamCore PRO Sessions. For SteamCoreSockets or IpNetDriver, you may need to use alternative methods like the Execute Console Command node with disconnect to leave the server.

Best Practices

  • Always test the disconnection process in a development environment to ensure proper cleanup and server-client communication.
  • Implement UI feedback to inform players of the disconnection status (e.g., a loading screen or confirmation message).
  • If using SteamCore PRO Sessions, ensure the session was properly created and joined before attempting to destroy it.
  • For games with frequent disconnections, consider adding reconnection logic or a retry mechanism in case of failures.