When a client connects to a server it is given an id (starting from 0, then 1 and so on). How can I get that id on the client side?
I tried NetworkManager.Singleton.LocalClientId
but it doesn’t work. The id I want is 1 but I get 18446744073709551615.
EDIT: 18446744073709551615 is the max value of ulong.
Thank you.
NetworkManager.Singleton.LocalClientId and the client id on the server should be the same. Which Netcode version are you using? It looks like you might be getting the transport id if you are on the earlier versions. (Wrong client ID passed to NetworkManager.OnClientConnectedCallback · Issue #1529 · Unity-Technologies/com.unity.netcode.gameobjects · GitHub)
Version 1.0.2
I upgraded to version 1.2.0 but still have this problem
You probably try to get that value BEFORE the client is connected. Do it in the OnClientConnected callback.
Thank you! I’ll try.
@lavagoatGG did CodeSmile’s suggestion solve your issue?
I didn’t have the time to try. I think it will solve it because I called NetworkManager.Singleton.LocalClientId right after starting a client. To move it after the client connects will be a lot of work (because I need the information on another script).