Search Unity

What's the difference between OnStartClient() and OnStartLocalPlayer() ?

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

  1. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    Title says it all.
     
  2. Freakyuno

    Freakyuno

    Joined:
    Jul 22, 2013
    Posts:
    138
  3. molx88

    molx88

    Joined:
    Apr 6, 2015
    Posts:
    6
  4. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    Well...to actually answer the question posted...

    OnStartClient is called by the NetworkManager and it works like any other hook. It's used when setting up a connected between the client and the server.

    OnStartLocalPlayer is called on the machine that is the local player. Most commonly it's used for executing things that should only happen for the local player (like GUI and camera set up).
     
  5. UnbreakableOne

    UnbreakableOne

    Joined:
    Nov 16, 2013
    Posts:
    168
    Thanks!
     
  6. AndyTheDishwasher

    AndyTheDishwasher

    Joined:
    Feb 20, 2022
    Posts:
    2
    Thanks for your explanation. However, I'm still a bit confused about the purpose of OnStartClient(). From what I've read in the api references, OnStartLocalPlayer() is supposedly called after OnStartClient(), but it doesn't explain why. When I spawn my player using the default Network Manager settings, I can't get my OnStartLocalPlayer() code to run when the player object appears. I haven't yet written an OnStartClient() function in my Network Manager, however, so I figure that's what I need to do, but I'm not sure how to go about it.
     
  7. Punfish

    Punfish

    Joined:
    Dec 7, 2014
    Posts:
    401
    It's basically legacy code saying the object spawned is for that player. It's imo redundant because you can just use OnStartClient and check if IsOwner/HasAuthority there.
     
    DRRosen3 likes this.
  8. AndyTheDishwasher

    AndyTheDishwasher

    Joined:
    Feb 20, 2022
    Posts:
    2
    That's an excellent idea! I'll definitely try that.
     
    Punfish likes this.