Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.15k stars 435 forks source link

ConnectedClients & ConnectedClientsList Not Updated on Distributed Authority Session Owner #3116

Open Moe-Baker opened 1 week ago

Moe-Baker commented 1 week ago

Description

Both NetworkManager.ConnectedClients & NetworkManager.ConnectedClientsList are not updated on the NetworkManager's session owner client, and only updated on the non-session owner clients. While NetworkManager.ConnectedClientsIds is updated accordingly on all clients.

Reproduce Steps

Put

if (NetworkManager.Singleton && NetworkManager.Singleton.IsConnectedClient)
      Debug.LogWarning($"Connected Clients Count: {NetworkManager.Singleton.ConnectedClients.Count} | {NetworkManager.Singleton.ConnectedClientsIds.Count} | {NetworkManager.Singleton.ConnectedClientsList.Count}");

in any Update Loop and connect two clients together, the session owner will print "Connected Clients Count: 1 | 2 | 1" when both clients are connected.

Actual Outcome

It's broken.

Expected Outcome

It not being broken.

Environment

NoelStephensUnity commented 1 week ago

@Moe-Baker Below is a replication of your steps using a generic project I use to run through issues: 3116_Replication.zip

You can find the code to check the client counts within the ExtendedNetworkManager.OnUpdateGUIConnected method on line 261: image

When using the above project, I am not seeing the same thing you are seeing. image

It really depends upon when you are checking those values since one is updated upon the initial connection accepted message and then a second message is received very shortly after that (around 1/2 RTT to the service) which provides the rest of the client information.

You will need to update the Services information to point to your own organization and most likely want to create a new cloud project prior to testing: image

Take a look at the attached project and let me know if that helps?