Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How does LocalClientId work?

Discussion in 'Netcode for GameObjects' started by lavagoat, Feb 1, 2023.

  1. lavagoat

    lavagoat

    Joined:
    Dec 19, 2020
    Posts:
    1
    Hello,
    I wanted to know how exactly does NetworkManager.Singleton.LocalClientId works. What is the number it represents?
    For example, let's say I have 3 clients - 0,1,2. Client 1 dissconects. Does the local client id's update to - 0,1 - or stays - 0,2?
    If another player joins will it be - 0,2,1 - or - 0,2,3?
    Thank you!
     
    lavagoatGG likes this.
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,609
    Consider this to be a unique identifier of connected clients only, no more no less. Ids of connected clients never change.

    If a client reconnects it could use any Id, possibly the next highest one but it may also be a formerly used Id that‘s been made available again. I think the docs mention this somewhere.
     
    lavagoatGG likes this.
  3. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    215
    Thanks.
    I want to check the order of the clients, but I can get the ConnectedClientIds only on server. Is there a way to check the order of the clients on each client? I am using the lobby service but it seems complicated to get the order through there.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    3,609
    Are you sure ConnectedClientList is server only? I don‘t think so but I can‘t say for sure.
    As an alternative you could send a ClientRpc with a list of Ids whenever a client connects or disconnects.
     
  5. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    215
    upload_2023-2-3_13-35-21.png
    It says so in the documentation.
    I will probably use clientRPC. Thank you