Hi,
I would like to access the Depth of Field parameter (especially Focal Length) via script. I am using Cinemachine 2.2.7 and the Post Processing Stack 2.0.17 if that matters.
Thanks in advance
Hi,
I would like to access the Depth of Field parameter (especially Focal Length) via script. I am using Cinemachine 2.2.7 and the Post Processing Stack 2.0.17 if that matters.
Thanks in advance
Cinemachine itself can only set basic lens settings such as FOV and near/far clip planes. For depth of field you need to use the PostProcessing stack. Put a layer on the main camera, and then create a PostProcessing extension on your vcam, with a profile that includes Depth of Field:
The profile settings themselves live in an asset, and are not meant to be modified at runtime. However, the CinemachinePostProcessing extension makes a special case for depth of field, and gives you some runtime control.
If you check Focus Tracks Target, then the focus distance will dynamically track the LookAt target of the vcam. The Offset parameter controls the offset from the target to the point that will be in focus. 0 puts the target exactly in focus, -1 put the focus point at 1m closer to the camera, and 1 will put it at 1m farther from the camera. If there is no LookAt target, then the offset is relative to the camera.
From code, just do vcam.GetComponent(), and you’ll have access to fields m_FocusTracksTarget and m_FocusOffset.
Okay thanks. I am already using it like that but I don’t think I can get the actual result I want like that… do you know if there is a way to exchange Post-Processing Profiles at runtime? Or would it be possible to attach 2 Cinemachine Post Processing Scripts on a single camera and activate/deactivate the components as I need the one or the other?
Otherwise I guess there is always the possibility to use multiple vcams with different Post Processing Profiles attached.
Any of those things are possibilities. You just have to try them and see what works best for you.
Thanks a lot!