Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Resolved OnClientConnectDisconnect returning wrong ID

Discussion in 'Netcode for GameObjects' started by Ed-Gilmour, May 20, 2024.

  1. Ed-Gilmour

    Ed-Gilmour

    Joined:
    Dec 14, 2021
    Posts:
    25
    I need these to get the client ID of the client that disconnects so I can detect if it was the host or not to take action, but whenever the host is the one that disconnects it returns the local ID of the client so there's no way of knowing if the host was the one that disconnected, this also happens the OnConnectionEvent :eek:. Any workarounds, or solutions is much appreciated!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,972
    Yes there is.

    The client didn't initiate the disconnect on purpose so when OnDisconnected returns that client's ID, you can assume that the session was ended by the server (host). I believe if the client merely loses Internet connection you get a transport error (additionally) so you can also handle that case.

    In all other cases where there is, say, a "Disconnect" button you remember that intent and when OnDisconnected runs you can be like "oh right, I intentionally disconnected". ;)
     
  3. Ed-Gilmour

    Ed-Gilmour

    Joined:
    Dec 14, 2021
    Posts:
    25
    That makes sense, thanks for the help and quick response!:D