I have FirstPersonCharacter (which is the camera).
I have a second game object that is the Post-process Volume (this comes in automatically when you start a new project in the LWRP template).
I used the code you gave me in a script (see below.)
I put the script onto the Post-process Volume.
I dragged the camera object into the public V2_Post Process field in the inspector.
So, thank you very much!
As bonus work, once you’d set me on the path, I also searched through the two scripts DepthOfField.cs and DepthOfFieldComponent.cs and found the names of the other Depth of Field properties, so now I can also address those in that same script (see it below).
So, with this information I can now do things like, when the camera moves, apply a blur to the Camera, and when it stops set the focus length back to normal to clear up the picture. By the way, the name of my script / class is LERP_Focal_Length.cs, but there is no lerp function in it (yet). That’s the next objective, so hopefully nobody is confused by that name.
Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
public class LERP_Focal_Length : MonoBehaviour
{
public int blur_amt = 1;
public PostProcessLayer v2_PostProcess;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
List<PostProcessVolume> volList = new List<PostProcessVolume>();
PostProcessManager.instance.GetActiveVolumes(v2_PostProcess, volList, true, true);
//
foreach (PostProcessVolume vol in volList)
{
PostProcessProfile ppp = vol.profile;
if (ppp)
{
DepthOfField dph;
if (ppp.TryGetSettings<DepthOfField>(out dph))
{
//dph.focusDistance.value = 69;
//dph.aperture.value = 30;
dph.focalLength.value = blur_amt;
//dph.kernelSize.value = KernelSize.VeryLarge;
}
}
}
}