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

Discussion Need your POV on a client list

Discussion in 'Netcode for GameObjects' started by CoryMelth, Oct 3, 2022.

  1. CoryMelth

    CoryMelth

    Joined:
    Oct 2, 2022
    Posts:
    4
    Hello, I’m a solo soldier on Unity and more than a beginner but less than advance level. I begin with Netcode and need tip.

    I would like to have a client list, more than just the ClientId. Ex: clientid, username, email.

    It is better to do an empty gameobject in the scene for each client and populate the empty gameobject with the informations?

    Better to do an empty gameobject and populate with fews list the inspector ?
     
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    My own solution to this is to have a scene object (ClientDataManager) that the server calls a method on whenever a client disconnects or connects (e.g.
    void AddClientData(ulong id,int team,string name)
    or
    void RemoveClient(ulong clientId)
    , it also has functions like
    bool NameIsInUse(string newName)
    ). This object exists for all everyone because it is a scene object, but is only populated on the server in my case because I do not want the clients to have info on the other clients – but either is possible with this setup. The ClientDataManager then fills and maintains a list of ClientData structs, which contain id, name, team id, player script references etc.

    Adding the clients is done in the approval check on the login script, where the data in the payload is passed to the ClientDataManager upon approval. Removing clients is done via the NetworkManager's
    OnClientDisconnectCallback
    .

    The way I set this up, the ClientDataManager is a MonoBehaviour and a singleton by the way, so non-networked, because only the server is allowed to access it. But it could just as well be a NetworkBehaviour that everyone can access.