diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index 9240ea120..c2df3bb61 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -424,18 +424,25 @@ internal static void OnTransportDisconnected(int connectionId) RemoveConnection(connectionId); // Debug.Log("Server lost client:" + connectionId); - // call OnDisconnected event. - // NetworkManager hooks into it with a virtual function to make - // DestroyPlayerForConnection(conn) optional, e.g. for PvP MMOs - // where players shouldn't be able to escape combat instantly. + // call OnDisconnected below. it's used in multiple places. OnDisconnected(conn); } } static void OnDisconnected(NetworkConnection conn) { - OnDisconnectedEvent?.Invoke(conn); - //Debug.Log("Server lost client:" + conn); + // NetworkManager hooks into OnDisconnectedEvent to make + // DestroyPlayerForConnection(conn) optional, e.g. for PvP MMOs + // where players shouldn't be able to escape combat instantly. + if (OnDisconnectedEvent != null) + { + OnDisconnectedEvent.Invoke(conn); + } + // if nobody hooked into it, then simply call DestroyPlayerForConnection + else + { + DestroyPlayerForConnection(conn); + } } static void OnError(int connectionId, Exception exception)