How to switch between cameras in Cinemachine
Now that we’ve learned how to set up virtual cameras, let’s take a look at how you can switch your view between them.
Objective: Learn about Virtual Camera Priority in Cinemachine, and how to switch between camera views by using the Inspector.
Switching Between Cameras in the Inspector
Switching your view is possible by using the Solo selector in the Inspector. This gives you an isolated view of your camera.
An example of Solo in action:
That’s great for testing out your different views, but the property we really want to look at for more dynamic changes is the Priority.
This property is how Unity measures the priority in which to display your cameras. That means that cameras with a higher priority number will be displayed before ones with a lower number.
A good way to visualize this is by Activating and Deactivating the Virtual Cameras. When you Deactivate the camera with the highest priority number, the next camera to be displayed will always be the one with the highest priority number after it.
Let’s see this in action!
This scene has four virtual cameras, their priorities go as follows:
- CM vcam1 = 20
- CM vcam2 = 7
- CM vcam3 = 9
- CM vcam4 = 15
When I Deactivate CM vcam1 from the Inspector, you can see that the camera view automatically changes. It goes from CM vcam1 to CM vcam4, it ignores any other cameras in between because it’s moving in priority order.
Now, if I deactivate both of the bigger priority cameras, the view should go to CM vcam3, which has the highest priority number among the two remaining cams.
Another way to do this is by actually scripting this behavior using C#, we’ll take a look at making interactable cameras in the next article!