Search Unity

Question How Do You Get The Local Player Object?

Discussion in 'Netcode for GameObjects' started by glowcouch, Aug 11, 2021.

  1. glowcouch

    glowcouch

    Joined:
    Aug 6, 2020
    Posts:
    3
    I haven't been able to find anything about this that works for me, I was using
    Code (CSharp):
    1. NetworkManager.Singleton.ConnectedClients.TryGetValue(NetworkManager.Singleton.LocalClientId, out var player
    but it only works for the host.
     
  2. danb1

    danb1

    Joined:
    Jun 14, 2019
    Posts:
    24
    From this documentation page:
    Code (CSharp):
    1. NetworkManager.Singleton.ConnectedClients[NetworkManager.Singleton.LocalClientId].PlayerObject;
     
  3. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    32
    Just curious, why not:

    networkManager.LocalClient.PlayerObject
     
    envman and brainwipe like this.
  4. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    Both should work
     
    r618 likes this.
  5. Kyperr

    Kyperr

    Joined:
    Jul 15, 2016
    Posts:
    32
    Okay. Was just wondering if perhaps there was a reason not to use the shorcuts on the networkmanager.
     
  6. My-Reality

    My-Reality

    Joined:
    Sep 3, 2020
    Posts:
    1
    Sorry to necropost but this was the top thread on Google

    connectedclients doesn't work anymore on the client side, only on the host

    I got it working with

    networkManager.LocalClient.PlayerObject

    like Kyperr mentioned
     
    Finijumper likes this.