Hi, I’ve read in the docs that it’s easy to use Cinemachine alongside an existing scripted camera and blend between vCams to the scripted one, but I have found no description of how to actually do that. I guessed that I’d just disable all vCams to make it happen, but that doesn’t seem to work. I’m specifically using the Corgi 2D engine and wanting to use Cinamachine for some specific purposes but retain the CorgiEngine camera during regular game play. In fact, when I add Cinemachine to a scene and disable and even remove both the brain component, and the vcam, it leaves the built-in Corgi camera broken.
Anyone know how to blend between scripted Cameras and vCam’s ?
It depends a little on how the custom camera script is set up. I’m going to assume that there is some game object with this custom script, and somewhere in there is a Unity Camera component. Here is what you need to do:
- Create a new Main Camera at the scene root. Just a Game Object with a Camera component.
- Add a CinemachineBrain component to that new Camera.
- In the custom script, replace the existing Camera component with a CinemachineVirtualCamera component. Put “Do Nothing” in both the Aim and the Body sections. That will allow the custom script to drive the transform of the vcam.
- If for whatever reason the custom camera script won’t allow you to delete the Camera component, just disable it instead.
Now, when you play the game, the custom script will drive the new Main camera, by virtue of the vcam component in it. When you want to blend to another vcam, just enable one. When you disable the new vcam it will blend back. Your scripted camera is now just another vcam, which drives the main Camera while it is Live.
Make sure that you have only one active Unity Camera in the scene (the one with the CM Brain on it), and no other CM brains.
2 Likes
Hey Gregoryl, Thanks seems to be working perfectly!
I took a few notes that may be useful to others wanting to do the same with the Corgi Engine.
- Modify Corgi’s CameraController script
- using Cinemachine
- Change references from Camera component to Cinemachine.CinemachineVirtualCamera, things like:
[RequireComponent(typeof(Camera))] → [RequireComponent(typeof(Cinemachine.CinemachineVirtualCamera))]
protected Camera _camera; → protected CinemachineVirtualCamera _virtualCamera;
_camera=GetComponent(); → _virtualCamera = GetComponent();
The Orthographic and OrthographicSize fields of the virtual camera are accessed through it’s Lens field:
if (_camera.orthographic==true) → if (_virtualCamera.m_Lens.Orthographic == true)
-
Some of your current camera settings need to be set in your new Camera component, others need to be set in your new CinemaMachineVirtualCamera component in the Lens section.
-
Make sure to Tag your new Camera as “Main Camera”, and remove the tag from your previous camera if you just disable it.
2 Likes