Search Unity

Get LocalPlayer gameobject on a client, The one spawned by AddPlayerForConnection?

Discussion in 'Multiplayer' started by CloudyVR, Sep 14, 2018.

  1. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    715
    I have a lobby manager that uses AddPlayerForConnection to add palyers to the lobby panel.

    But how do I find the Gameobject that was added on a client?

    Network.player - has no reference to any transforms or script componets.
    NetworkManager.singleton.client - has no reference to any transforms or script componets.

    What am I missing? Why can't I simply reference the local lobby player gameobject?

    Only way I can imagine now is loop through all LobbyPlayers in scene and search for the one that isLocalPlayer = true?

    If that is the only way then that is absolutely insane!
     
    Last edited: Sep 14, 2018
  2. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    715
    I think I found it after stepping back for a moment:

    Code (csharp):
    1. var lobbyInfo = NetworkManager.singleton.client.connection.playerControllers[0].gameObject;