How to switch between cameras?

I just read the blog post tutorial and they mention that you should set up multiple cameras and switch between them. But how are we supposed to do this? I know how to turn off a camera and turn another one on, but surely that can’t be what they mean? There must be some kind of smooth transition system?

Thanks. :slight_smile:

Indeed there is. You have one Unity camera, with a Cinemachine Brain component. That stays on all the time.

Then, you have multiple Virtual Cameras that you activate and deactivate as needed. Simply activate/deactivate their GameObjects. The Brain will take care of the blending.

3 Likes

So would that be as simple as writing this? gameObject.SetActive(bool);

1 Like

Yes.
You can also deactivate the outgoing vcam at the same time.
Control the transitions from the Brain:

3578157--289085--upload_2018-7-27_14-15-15.png

1 Like

Hi, may i know can i have one main camera without a Cinemachine Brain component, second camera with Cinemachine Brain component and multiple virtual camera? and switch between them, is it will work

Yes it will work. The vcams will control the CMBrain camera, the other camera is free.

1 Like

OK Thanks, I will try to figure out

You can have multiple CM Brains in the scene. Each will filter vcams according to the culling mask in the associated camera. Active vcams on the visible layers will drive the brain. There is no hard link.

1 Like

What version of post-processing are you using? And are you using HDRP or URP?

What is the best way to switch cameras in terms of performance? Activate/deactivate their GameObjects, increase/decrease their Priority, or to use MoveToTopOfPrioritySubqueue() function?

Thanks in advance!

Unless you are trying to change cameras a thousand times every Update(), none of these will have any impact on your game’s performance. This is thinking backwards-- you should run the game, measure the game’s performance in the profiler tools, find the thing that is holding your game back from performing well, and go fix that, IN THAT ORDER.

1 Like

Thank you very much for answer! I am relatively new to Unity, so this really helps… Best regards!

would disabling the main camera and enabling the second camera work