Contents - Quick Links
uLink network logic : Creator-Owner-Proxy
It is now time to introduce a very important concept to go forward in this authoritative server tutorial using uLink unity network library, the way the ulink authoritative server instantiates gameobjects and synchronizes them between clients.
The server instantiates three important prefabs when a player connects, Creator, Owner and Proxy. All of them are used in the script Spawner, that we are going to write for the next tutorial step, when a player connects to the server. Only the server can do uLink.Network.Instantiate() in an authoritative setup, clients are incapable of doing this to avoid cheating. So let’s create this Spawner script :
- In the Inspector panel create a folder named Scripts and inside it create a new C# script named Spawner
- Inside the Spawner C# script, insert the following code :
- Create an empty gameobject in the server scene and name it Spawn and add as a component the Spawner script.
Looking at the Spawner script code the first part, the public variables declaration, serves to make assignable via the Inspector the three prefabs that will be used and to set the spawn location of new players. The uLink_OnPlayerConnected function is called when a player connects and calls a uLink.Network.Instantiate function that read the Creator, owner ,proxy and spawnlocation variables and instantiates them correctly on server and clients.
Owner is the prefab instantiated on the client for the player’s character. Motion of this object is controlled by the player. It is connected to the camera in the “Client” scene. We will need to write another script to put the camera on the client behind the back of the player.
Creator is the prefab instantiated on the server for every player connecting to the game. It has fewer scripts than Owner because we don’t need fancy effects on the server, we could make the server even without the camera.
Proxy prefab is instantiated in clients for all the opponent players’ characters.