Cinemachine: how can I store the current active virtual camera into a variable?
Basically I'd like to get the current live virtual camera and store it in a CinemachineVirtualCamera variable.
public CinemachineBrain cine;
public CinemachineVirtualCamera VirtualCamera;
void Start()
{
VirtualCamera = cine.ActiveVirtualCamera;
}
But it gives me an error that says: "Can't convert type Cinemachine.ICinemachineCamera to Cinemachine.CinemachineVirtualCamera"
I've already tried casting but it doesn't work, the variable remains null.
I've also tried:
VirtualCamera = cine.ActiveVirtualCamera.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
Can someone help me please?
Answer by RemDust · Jan 03, 2021 at 01:19 PM
I know this is old but just in case :
What you need is something like :
var brain = CinemachineCore.Instance.GetActiveBrain(0);
var Vcam = brain.ActiveVirtualCamera.VirtualCameraGameObject.GetComponent<CinemachineVirtualCamera>();
Your answer
Follow this Question
Related Questions
Help with switching between multiple virtual cameras 0 Answers
Canvas world space Mode error in vr camera 0 Answers
Why are my keys being registered multiple times? 1 Answer
How can i play Animation clip using Animator on other camera then Main Camera ? 1 Answer
Can i do an app in "2D" that changes in VR mode when i want? 0 Answers