Search Unity

How come NetworkBehaviour.isLocalPlayer is false on OnStartClient() ?

Discussion in 'Multiplayer' started by Jordii, Mar 9, 2016.

  1. Jordii

    Jordii

    Joined:
    Sep 14, 2010
    Posts:
    135
    Basically, at OnStartClient() I want to detect whether this is the localPlayer or not (I know of the OnStartLocalPlayer function). This always returns false. If I check it in the Update() cycle, it will turn true. How come UNET is not aware whether it's the local player's NetworkBehaviour at OnStartClient()?
     
  2. molx88

    molx88

    Joined:
    Apr 6, 2015
    Posts:
    6
    The variable isLocalPlayer simply has not been set yet when OnStartClient() is called. It is assigned after OnStartClient() is called.

    What are you trying to accomplish on the OnStartClient() function?
     
  3. Jordii

    Jordii

    Joined:
    Sep 14, 2010
    Posts:
    135
    Bumping this really old thread of mine. In short, I basically want to register a "Player" NetworkBehaviour when it's initialized, and let the service where it's registering know whether it's the one that has spawned locally or not. OnStartClient() doesn't know. OnStartLocalClient() of course does, but that won't trigger for non-locals. Start() does seem to work, but I'm not sure this is the right moment to check for this.

    So what is the right to time to check for this?
     
    SomeAlexander likes this.
  4. Jordii

    Jordii

    Joined:
    Sep 14, 2010
    Posts:
    135
    Bump, anyone?
     
  5. Jos-Yule

    Jos-Yule

    Joined:
    Sep 17, 2012
    Posts:
    292
    You should read the UNET source code and/or experiment to ensure that Start is _always_ called after the OnStartXXX() overrides. I'm pretty sure it is, but i wouldn't say "yes" to you because i'm not that sure.