Search Unity

Question How do I link Lobby Players to Unity NGO NetworkObjects?

Discussion in 'Lobby' started by WakingDragon, Nov 11, 2022.

  1. WakingDragon

    WakingDragon

    Joined:
    Mar 18, 2018
    Posts:
    41
    Sorry if this is somewhere in the docs but I am struggling with a sensible way to link my Player instances (that exist in the Lobby) with spawned NetworkObjects. Is there a simple way of doing this?

    Here is the context:
    • I am using a Lobby which is working super-well.
    • When sufficient Players have joined and are "ready" (they have clicked a button that updates a PlayerDataObject to say they are ready), then the host can click "start game"
    • When "start game" is clicked, a lobby DataObject is updated to say "ServerStarted" - the host NetworkManager triggers StartHost
    • The client reads the ServerStarted DataObject and this triggers the client NetworkManager to StartClient
    • Both instances of NetworkObjects appear on both Host and Client.
    • But is there a way to tell the NetworkManager which Player.Id belongs to which?
    My Lobby Player object carries some useful data like the colour, the player name, etc. It feels like there should be a key to validate that they are both part of the same authenticated player.

    Thanks
    Ben
     
    ba55yunky likes this.
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,887
  3. ba55yunky

    ba55yunky

    Joined:
    Nov 29, 2018
    Posts:
    7
  4. DogDogCatDeveloper

    DogDogCatDeveloper

    Joined:
    Jan 4, 2023
    Posts:
    2
  5. DogDogCatDeveloper

    DogDogCatDeveloper

    Joined:
    Jan 4, 2023
    Posts:
    2
    finally, it goes to SetupClientConnectionAsync(), looks like it is same as SetPlayerIdClientRpc(playerId, clientId), both way is client sending their PlayerId to server, i am a little confused, is this safe?