Legacy Documentation: Version 5.1
The High Level API
Using the NetworkManager

Network System Concepts

Server and Host

In the unity networking system, games have a Server and multiple Clients. When there is no dedicated server, one of the clients plays the role of the server - we call this client the “host”.

The host is a server and a client in the same process. The host uses a special kind of client called the LocalClient, while other clients are RemoteClients. The LocalClient communicates with the (local) server through direct function calls and message queues, since it is in the same process. It actually shares the scene with the server. RemoteClients communicate with the server over a regular network connection.

A goal of the networking system is that the code for LocalClients and RemoteClients is the same, so that developers only have to think about one type of client most of the time.

Instantiate and Spawn

In Unity, GameObject.Instantiate creates new Unity game objects. But with the networking system, objects must also be “spawned” to be active on the network. This can only be done on the server, and causes the objects to be created on connected clients. Once objects are spawned the Spawning System does distributed object life-cycle management and state synchronization.

For more details see Spawning.

Players, Local Players and Authority

In the network system, player objects are special. There is a player object associated with each person playing the game, and commands are routed to that object. A person cannot invoke a command on another person’s player object - only their own. So there is a concept of “my” player object. When a player is added and the association is made with a connection, that player object becomes a “local player” object on the client of that player. There is a property isLocalPlayer that is set to true, and a callback OnStartLocalPlayer() that is invoked on the object on the client. The diagram below shows two clients and their local players.

Only the player object that is “yours” will have the isLocalPlayer flag set. This can be used to filter input processing, to handle camera attachment, or do any other client side things that should only be done for your player.

In addition to isLocalPlayer, a player object can have “local authority”. This means that the player object on its owner’s client is responsible for the object - it has authority. This is used most commonly for controlling movement, but can be used for other things also. The NetworkTransform component understands this and will send movement from the client if this is set. The NetworkIdentity has a checkbox for setting LocalPlayerAuthority.

For non-player objects such as enemies, there is no associated client, so authority resides on the server.

There is a property “isAuthority” on the NetworkBehaviour that can be used to tell if an object has authority. So non-player objects have authority on the server, and player objects with localPlayerAuthority set have authority on their owner’s client.

The High Level API
Using the NetworkManager