Search Unity

Controlling DOF with C# on Post Processing Stack v2?

Discussion in 'General Graphics' started by unfungmz, Jan 27, 2019.

  1. unfungmz

    unfungmz

    Joined:
    Jul 29, 2017
    Posts:
    162
    Any way to control depth of field parameters in runtime via code (post processing v2). I found some code, but I'm getting errors trying to set ---

    PostProcessVolume volume = Cam.GetComponent<PostProcessVolume>();
    DepthOfField MyDOF;

    volume.profile.TryGetSettings(out MyDOF);
    MyDOF.focusDistance = 1.0f;

    error CS0029: Cannot implicitly convert type `float' to `UnityEngine.Rendering.PostProcessing.FloatParameter'
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  3. NIOS

    NIOS

    Joined:
    Jul 12, 2014
    Posts:
    59
    This didn't show for autofill for me so it was a miracle I found it, but you can just use and assign MyDOF.focusDistance.value
     
    Snake-M3 and frost4mage like this.