-
Notifications
You must be signed in to change notification settings - Fork 464
Description
Description
My goal is to track player states when they are initiating connection and when their connection fails for some reason before completing it. I cannot use OnClientDisconnectCallback since it is triggered only after client disconnects after successful connection is established.
I decided to subscribe to the NetworkTransport events
NetworkManager.Singleton.NetworkConfig.NetworkTransport.OnTransportEvent += OnTransportEvent;
and handle a particular set of events
private void OnTransportEvent(NetworkEvent eventType, ulong clientId, ArraySegment<byte> payload, float receiveTime)
{
switch (eventType)
{
case NetworkEvent.Connect:
if (NetworkManager.Singleton.LocalClientId != clientId)
{
Debug.Log($"[Transport] Client {clientId} attempting to connect...");
}
break;
case NetworkEvent.Disconnect:
if (NetworkManager.Singleton.LocalClientId != clientId)
{
Debug.Log($"[Transport] Client {clientId} connection lost or failed.");
}
break;
case NetworkEvent.Data:
// Ignore or handle raw transport data if needed.
break;
}
}
The issue I see here is that OnTransportEvent receives the clientId that is supposed to be the clientId of the player that is connecting but the value does not match the actual clientId that is stored in NetworkManager.Singleton.ConnectedClients after the connection is established.
Actual Outcome
clientId on transport events DOES NOT match the client id that is stored in NetworkManager.Singleton.ConnectedClients and is sent by OnClientConnectedCallback and OnClientDisconnectedCallback events
Expected Outcome
The clientId value must be the same for all events
Environment
- OS: Win11
- Unity Version: [e.g. 2022.3.62f]
- Netcode Version: [e.g. 1.14.1]
- Netcode Topology: Client-Server