Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Get Network Object Id from Client Id

Discussion in 'Netcode for GameObjects' started by mitio31, May 28, 2021.

  1. mitio31

    mitio31

    Joined:
    Apr 17, 2020
    Posts:
    3
    Hello!
    I have a problem, which I do not know how to resolve without rewriting a lot of code.
    So I decided to ask if someone knows how can my problem be resolved without doing that.
    The problem is that I have to store in array or list the network object Ids of all the connected clients.
    When a client disconnects, I want to remove his Id from the array/list. But the problem is that NetworkManager.Singleton.OnClientDisconnectCallback gives you clientId as a parameter. I cannot call NetworkManager.Singleton.ConnectedClients[clientId].PlayerObject, because this object is no longer there (the client disconnected).
    If someone can tell me how can I get the network object ID of the disconnected client I will be really grateful!
    Thanks in advance!
     
    filip-mixedworld likes this.
  2. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    I think the only way to do this currently would be to manually keep track of a id/gameobject dictionary foreach of your player objects and use that to find the player object.
     
    cj-currie likes this.