Unity and Cinemachine — (Re)Introducing Virtual Cameras
The Cinemachine virtual camera is easy to work with and very versatile
A few months ago, I wrote a short series of articles on the subject of cinematography in Unity. Now I want to continue on that subject and get even more in-depth on both Cinemachine and Timeline.
Today we’re going to re-familiarize ourselves with the subject of virtual cameras — the foundational element of Cinemachine — and possibly learn a few new things as well.
What is Cinemachine?
Cinemachine is a package available for Unity that provides tools for managing in-game cameras. Without it, we may need to do a lot of development work to get the functionality we want for our cameras.
Cinemachine is freely available for all Unity projects. To install it, make use of the Unity package manager (which can be found in the Window menu).
You can find the Cinemachine package in the Unity Registry section of Packages.
What is a Virtual Camera?
The virtual camera is the foundational tool of Cinemachine. It’s through the virtual cameras that all of the benefits of the Cinemachine package are realized.
In spite of the name, virtual cameras are not actually cameras. In standard Unity, there is only one active camera. Virtual cameras act more like camera operators. When you set the position, rotation, and various configurable options on the virtual cameras, those settings will then be applied to the actual camera when that virtual camera is active.
Making Virtual Cameras
With the Cinemachine package installed in your project, you should now see an option in the menu bar for “Cinemachine”.
Within that menu, you can see several options, and at the top is “Create Virtual Camera”. Selecting that create a new virtual camera. That’s all there is to it!
Many of the other options also create virtual cameras with specialized options, but’s that a topic for another time.
Managing your virtual cameras
When you start creating and making use of virtual cameras, you might notice in your Game window that your view is that of one of your virtual cameras. If you have more than one, however, it may not be obvious to you which one is in control and how to change it.
We’ll need to see our Inspector window to check out our options for managing the virtual cameras.
The first way to determine which virtual camera is in control is by simply disabling all virtual cameras but one. Kind of ham-fisted perhaps, but it’s a valid method and there’s no surer way to guarantee that there’s only one virtual camera the main camera could be picking up from.
The second method is by using the Solo button, which can be found at the top of the CinemachineVirtualCamera component options. Selecting this button will make the virtual camera in question the one that the main camera makes use of.
This is good for checking cameras while building your project, but from my understanding it’s not meant to be used at runtime. Keep that in mind.
The final, and arguably best, way to manage your virtual cameras is by making use of the Priority field in the CinemachineVirtualCamera options. The virtual camera with the highest Priority value is the dominant virtual camera, and this value can absolutely be changed during runtime to switch between virtual cameras.
The three states of virtual cameras
Related to managing your virtual cameras, it’s good to know about the three states that Cinemachine virtual cameras can be in.
The first possible state is Live. Live means this virtual camera is the one being used by the main camera to display visuals. Depending on options, it will be actively tracking its target.
The second possible state is Standby. Standby means this virtual camera is not the one being used by the main camera, but it still may be actively tracking a target. A virtual camera would be in Standby if there were another enabled virtual camera with a higher Priority value.
The third possible state is Disabled. Disabled virtual cameras are not used by the main camera and are not actively tracking any target. This is true regardless of the value of its Priority field.
Ok, now that we have reminded ourselves of what virtual cameras are and what they can do, now we can dive further into the realm of Cinemachine! Next time, we’ll be doing a more in-depth exploration of the Aim options for a virtual camera. Until then, thanks for reading.