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

Title says it all.

http://docs.unity3d.com/ScriptReference/Networking.NetworkManager.OnStartClient.html
http://docs.unity3d.com/ScriptReference/Networking.NetworkBehaviour.OnStartLocalPlayer.html

Even though the documentation for Unity can be “sketchy” at best in places. If you’re going to be a programmer, you need to learn how to read / utilize an API reference. It’ll save you SO many headaches. :slight_smile:

https://bitbucket.org/Unity-Technologies/networking

Link to the bit bucket account where you can see the source code of how the Unity networking works.

I tend to look at this over the documentation.

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).

12 Likes

Thanks!

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.

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.

1 Like

That’s an excellent idea! I’ll definitely try that.

1 Like