Basic Setup with Cinemachine
Managing a Cinemachine Camera in multiplayer.
This guide will show you one way you can set-up your player camera for multiplayer when you are using the Cinemachine package.
Installing Cinemachine
The first step — if you haven't done so already — is to install Cinemachine through the Unity Package Manager.

Adding the Cinemachine Brain
Now that we have Cinemachine installed we can set it up. Add the Cinemachine Brain component to the Main Camera game object in the scene.

Giving the Player a Camera Holder
Now create an empty Game Object on your Player Prefab and position it where you'd like. This will be our container for the Cinemachine Camera.

Adding the Cinemachine Camera
Now simply add the Cinemachine Camera component to the newly created CameraHolder game object.

Writing a PlayerCamera Script
Let's now add the following script to the Player Prefab that we will use to take control of our Camera once our player spawns in.
using FishNet.Object;
using Unity.Cinemachine;
using UnityEngine;
// This script will be a NetworkBehaviour so that we can use the OnStartClient override.
public class PlayerCamera : NetworkBehaviour
{
[SerializeField] private CinemachineCamera cinemachineCamera;
// This method is called on the client after the object is spawned in.
public override void OnStartClient()
{
// Simply enable our local cinemachine camera on the object if we are the owner.
cinemachineCamera.enabled = IsOwner;
}
}
This script uses the OnStartClient override method from NetworkBehaviour to enable or disable the Cinemachine Camera component on the player objects depending on if they are our local player or not.
Assign your References to the Script
Now select the Player Camera component in your Player Prefab and add drag the Camera Holder game object into the Cinemachine Camera field to assign it the component.

Test the Camera In-Game
With all that set you should be able to run the game and see how the camera from the scene is controlled by only your local player.

Last updated