Search Unity

Resolved How to get the is of the client on the client side?

Discussion in 'Netcode for GameObjects' started by lavagoatGG, Mar 13, 2023.

  1. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    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.
     
    Last edited: Mar 13, 2023
  2. afavar

    afavar

    Joined:
    Jul 17, 2013
    Posts:
    68
  3. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Version 1.0.2
     
  4. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    I upgraded to version 1.2.0 but still have this problem
     
  5. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,956
    You probably try to get that value BEFORE the client is connected. Do it in the OnClientConnected callback.
     
  6. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Thank you! I'll try.
     
  7. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    @lavagoatGG did CodeSmile's suggestion solve your issue?
     
  8. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    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).