Assign VCam at runtime by name?

Hey! First time making a game and I’m struggling with assigning some cameras.

Is it possible to assign a virtual camera at runtime by name? When the player joins the arena, it creates them, a follow camera, and a zoom camera. Both the ZoomCamera and the FollowCamera instantiate into the scene before the player’s prefab so it should be able to find them right?
7578403--939079--upload_2021-10-16_17-32-30.png
It’s an online multiplayer game and I activate and deactivate the specific camera when the aim button is pressed. I get the behavior I want when I pause, and drag and drop the aim cam into the serialized field I made to test this with.
Before (not working):
7578403--939088--upload_2021-10-16_17-34-6.png
After (Working):
7578403--939091--upload_2021-10-16_17-34-26.png

At runtime, how do I find a Virtual camera in the scene and then assign it to be the CinemachineVirtualCamera that field looks for?

Thanks!

See here:

then you can get the CinemachineVirtualCamera component from the returned result and assign it to the field in your ZoomCamera script.

1 Like

That Worked! Thank you so much! It took a little mixing around to get the typing to work, as it kept saying that it can’t convert GameObject to CinemachineVirtualCamera, so this was my solution that ended up working:
7589356--941065--upload_2021-10-20_17-47-55.png

7589356--941062--upload_2021-10-20_17-47-44.png