For the complete documentation index, see llms.txt. This page is also available as Markdown.

Client Authoritative

This tutorial shows how to make the third person starter asset multiplayer in a client authoritative way.

1

Before we begin

Don't forget to import the third person starter asset into your project and ensure it's working correctly in your Unity version, input system, and rendering pipeline.

2

Import FishNet

Let's begin by importing Fish-Networking. You can use the free or pro version for this tutorial, and you can get it from the GitHub, Asset Store, or Asset Package. See Installing Fish-Networking for assistance with this step.

3

Create the NetworkManager

With FishNet imported we can now get started with turning the singleplayer setup into a multiplayer one. Open up the Playground scene — or your own scene, if you already have one — and drag in the NetworkManager prefab from the FishNet/Demos/Prefabs folder.

This will allow us to connect instances of the game to each other through the provided network HUD.

4

Prepare the player components

Next, we’ll prepare the player object for network synchronization. Open the PlayerArmature prefab located in Assets/StarterAssets/ThirdPersonController/Prefabs and add the following components: NetworkObject, NetworkTransform, and NetworkAnimator.

  • NetworkObject links the prefab across the network.

  • NetworkTransform synchronizes its position and rotation.

  • NetworkAnimator ensures animations are synchronized.

Together, these components enable the player to stay consistent across all connected clients. The default settings of these components should work, just ensure Client Authoritative is enabled on both the NetworkTransform and NetworkAnimator, the Animator field is set on the NetworkAnimator, and the Component Configuration field is set to CharacterController in the NetworkTransform.

5

Setup the player code

We now need to make sure the players can only move their own player objects. Open up the ThirdPersonController script and change it from inheriting from MonoBehaviour to NetworkBehaviour — this will require adding using FishNet.Object; to the top of your code.

public class ThirdPersonController : NetworkBehaviour

This code will allow us to make use of NetworkBehaviour properties, methods, and so on.

With that done, we can add the following code to the top of the Update and LateUpdate methods:

if (!IsOwner)
    return;

This code will prevent the method from running on objects the player doesn't own, thus ensuring he can only move and control his own player.

They should look like this now:

private void Update()
{
    if (!IsOwner)
        return;

    _hasAnimator = TryGetComponent(out _animator);

    JumpAndGravity();
    GroundedCheck();
    Move();
}

private void LateUpdate()
{
    if (!IsOwner)
        return;

    CameraRotation();
}
6

Set up the camera

One thing we still need to do is tell the camera which player it should be following. We'll do that by instantiating a follow camera when our local player spawns in. Inside the ThirdPersonController script, add the following field:

[Tooltip("The Follow Camera prefab that we spawn for the owner")]
public CinemachineVirtualCamera PlayerFollowCameraPrefab;

Then add this override method.

public override void OnStartClient()
{
    if (!IsOwner)
        return;

    CinemachineVirtualCamera virtualCam = Instantiate(PlayerFollowCameraPrefab);
    virtualCam.Follow = CinemachineCameraTarget.transform;
}
7

Set up the references

Now we can delete the PlayerFollowCamera object from the scene and instead assign that prefab into our PlayerArmature's PlayerFollowCameraPrefab field.

Finally, we will delete the PlayerArmature object from the scene and assign that prefab into our NetworkManager's PlayerPrefab field.

8

Try it out!

You are now ready to test your game. Launch multiple instances of it and start one as a server and client and the other/s as a client.

You can launch a second Unity Editor instance by using Unity's Multiplayer Play Mode package or a third-party package such as ParrelSync. Find out more about these options and how to use them with this tutorial: Testing with Multiple Editors.

Last updated