MMO multiplayer tutorial for Unity with uLink authoritative server

MMO multiplayer tutorial for Unity with uLink authoritative server

Share

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 :

[snippet id=’112′]

  • Create an empty gameobject in the server scene and name it Spawn and add as a component the Spawner script.

Spawner.cs script download

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.

4 thoughts on “MMO multiplayer tutorial for Unity with uLink authoritative server

  1. I have tried tow ork on this. Somehow my client is stuck in “Instantiating”. I am able to move it though but without any effect on the server. The model seems to come back to the spawn point after any movement in the client.

    • Hi ! Do you use the same Unity and uLink versions of this tutorial? I should check and validate this tutorial also with the latest versions. However the issue you refer to is something i recall experiencing while i was coding, the server is overwriting the transform component, please check your project ,every option of the creator owner and proxy objects should match the tutorial.
      Meanwhile i will review the tutorial to check for bugs, maybe we can sort out your problem together.

      Also after a quick look i added a page with a video of the final result you should get, and a link to the project and compiled files. Carefully check the uLink Network view component options of the Proxy, Owner and Creator gameobjects.

      Thanks for your comment !

  2. I could not switch from manual view id to allocated until i had draged the creator prefab into the project folder! just a heads up for anyone who might have the same problem.

Leave a Comment