Course contentsShow
← Unity Game Development
Lesson 392 of 8286. Animation and CinemachineFree lesson

Managing Multiple Virtual Cameras with Priority Levels

Learners will control active camera states by manipulating the priority property to switch perspectives dynamically based on gameplay events and triggers.

In this lesson, you will learn how to orchestrate dynamic perspective shifts by programmatically adjusting the Priority property of your Cinemachine Virtual Cameras.

Understanding Camera Priority

When you have multiple Virtual Cameras in a scene, the CinemachineBrain component on your Main Camera constantly monitors them to decide which one should be "live." It uses a simple rule: The camera with the highest Priority value wins.

Think of Priority like a stack of layers; if Camera A has a priority of 10 and Camera B has a priority of 20, the Brain will automatically switch to Camera B. When you want to return to Camera A, you simply lower Camera B’s priority below 10. This is the foundation for creating seamless, event-driven cinematics without needing to manually enable or disable game objects.

Implementation Logic

To switch perspectives during gameplay, you need to reference the CinemachineVirtualCamera component in your script and modify its Priority integer.

For example, if you want to switch to a "Close-Up" camera when a player enters a specific trigger zone, your script would look like this:

using UnityEngine;
using Cinemachine;

public class CameraSwitcher : MonoBehaviour
{
    public CinemachineVirtualCamera closeUpCam;

    private void OnTriggerEnter(Collider other)
    {
        // Boosting the priority makes this camera the active one
        closeUpCam.Priority = 20;
    }

    private void OnTriggerExit(Collider other)
    {
        // Lowering it lets the previous camera (with lower priority) take over
        closeUpCam.Priority = 0;
    }
}

Why This Matters

By manipulating the Priority rather than calling SetActive(false), you allow the CinemachineBrain to handle the heavy lifting. Because the Brain knows about all cameras, it can calculate a smooth interpolation (or "blend") between the old camera and the new one based on the settings defined in the Brain component. This keeps your scene transitions feeling professional and polished rather than jarringly abrupt.

Key Takeaway: The CinemachineBrain always delegates control to the Virtual Camera with the highest Priority integer; simply script changes to these values to trigger fluid, dynamic perspective shifts during your game.