Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Question Get SteamId from NetworkManager's side? Detect on Host if he lost internet connection?

Discussion in 'Netcode for GameObjects' started by Takii, Apr 25, 2023.

  1. Takii


    Sep 5, 2017
    Hey there. I am using Netcode for Gameobjects with FacepunchTransport and Facepunch.Steamworks.

    I've 2 main questions:

    1. How can I retrieve the SteamId in the OnClientConnectedCallback and the OnClientDisconnectedCallback? The Id's on the NetworkManager of course are no SteamId's but just 0(host), 1, 2, 3, ..... (clients). So i wonder if there is a proper way to retrive the clients SteamId over the NetworkManager, or if i have to manually assign it through the steam lobby?

    2. How can I detect on the Host side, if he lost Internet connection? For Clients the OnClientDisconnectedCallback Event will fire, but not for the Host himself. So whats the best way to detect that, in best case with the already given Tools/Features?

    Thats some code for reference, so you know what Events i am talking about & how i handle Host Disconnect detection for the Clients (also is the Host ALWAYS ID 0? Or should i better check with the OwnerID?):

    Code (CSharp):
    1. private void OnEnable() {
    2.     NetworkManager.Singleton.OnClientDisconnectCallback += OnClientDisconnectCallback;
    3.     NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnectCallback;
    4. }
    6. private void OnDisable() {
    7.     NetworkManager.Singleton.OnClientDisconnectCallback -= OnClientDisconnectCallback;
    8.     NetworkManager.Singleton.OnClientConnectedCallback -= OnClientConnectCallback;
    9. }
    11. private void OnClientConnectCallback(ulong id) {
    12.     // How to get the SteamId?
    13. }
    15. private void OnClientDisconnectCallback(ulong id) {
    16.     // How to get the SteamId?
    18.     // +
    20.     // How can I detect for the host himself if he lost internet connection? OnClientDisconnectCallback does not fire in that case at all
    22.     Debug.Log("OnClientDisconnectCallback: " + id.ToString());
    24.     if (IsClient) {
    25.         if (id == 0) { // 0 = host?!
    26.             LobbySaver.instance.currentLobby?.Leave();
    27.             LobbySaver.instance.currentLobby = null;
    28.             NetworkManager.Singleton.Shutdown();
    30.             SceneManager.LoadScene("MainMenu");
    31.         }
    32.     }
    33. }
    Thanks in advance for any help!

    Greetings from Vienna & have a nice day :)
  2. fernando-a-cortez


    Unity Technologies

    Dec 14, 2020

    For number 1: there's no way to retrieve the SteamId of a user through NetworkManager. You'll have to manage that information yourself. Take a look at Boss Room's SessionManager for an example of handling a player's session data:

    For number 2: As of Netcode for GameObjects v1.4.0 (see release here:, a OnServerStarted and OnServerStopped callback have been introduced to determine when the server has been started or is no longer active.

    I hope that helps!
    RikuTheFuffs likes this.