Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Why am I getting error on TryGetSettings when using postprocessing v2 ?

Discussion in 'Editor & General Support' started by benziavrumi, Apr 28, 2020.

  1. benziavrumi

    benziavrumi

    Joined:
    Apr 19, 2020
    Posts:
    10
    In the editor on my Camera I added two components : Post Process Layer and Post Process Volume
    On the first component the layer I changed the Layer to a layer I added PostProcessing
    On the second component I set the Is Global to true and added one effect for now Depth Of Field

    Now I want to change and set values to the Depth Of Field Focal Length via a script.
    So I created a new script :

    Code (csharp):
    1.  
    2.     using System.Collections;
    3.     using System.Collections.Generic;
    4.     using UnityEngine;
    5.     using UnityEngine.Rendering.PostProcessing;
    6.    
    7.     public class PostprocessingEffects : MonoBehaviour
    8.     {
    9.         private PostProcessVolume postProcessVolume;
    10.         private PostprocessingEffects depthOfField;
    11.    
    12.         void Start()
    13.         {
    14.             postProcessVolume = GetComponent<PostProcessVolume>();
    15.             postProcessVolume.profile.TryGetSettings(out depthOfField);
    16.         }
    17.    
    18.         // Update is called once per frame
    19.         void Update()
    20.         {
    21.    
    22.         }
    23.    
    24.         /*public GameObject player;
    25.         public bool dephOfFieldFinished = false;
    26.    
    27.         private PostProcessVolume postProcessVolume;
    28.         private DepthOfField depthOffield;
    29.         private Animator playerAnimator;
    30.         private float clipLength;
    31.         private Coroutine depthOfFieldRoutineRef;
    32.    
    33.         // Start is called before the first frame update
    34.         void Start()
    35.         {
    36.             postProcessVolume = GetComponent<PostProcessVolume>();
    37.         }
    38.    
    39.         private void OnEnable()
    40.         {
    41.             if (depthOfFieldRoutineRef != null)
    42.             {
    43.                 StopCoroutine(depthOfFieldRoutineRef);
    44.             }
    45.    
    46.             playerAnimator = player.GetComponent<Animator>();
    47.    
    48.             clipLength = playerAnimator.GetCurrentAnimatorStateInfo(0).length;
    49.            
    50.             var depthOfField = postProcessingProfile.depthOfField.settings;
    51.             depthOfField.focalLength = 300;
    52.             StartCoroutine(changeValueOverTime(depthOfField.focalLength, 1, clipLength));
    53.             postProcessingProfile.depthOfField.settings = depthOfField;
    54.             // Don't forget to set depthOfFieldRoutineRef to null again at the end of routine!
    55.         }
    56.    
    57.         IEnumerator changeValueOverTime(float fromVal, float toVal, float duration)
    58.         {
    59.             //playerLockManager.PlayerLockState(true, true);
    60.    
    61.             float counter = 0f;
    62.    
    63.             while (counter < duration)
    64.             {
    65.                 var dof = postProcessingProfile.depthOfField.settings;
    66.    
    67.                 if (Time.timeScale == 0)
    68.                     counter += Time.unscaledDeltaTime;
    69.                 else
    70.                     counter += Time.deltaTime;
    71.    
    72.                 float val = Mathf.Lerp(fromVal, toVal, counter / duration);
    73.    
    74.                 dof.focalLength = val;
    75.                 postProcessingProfile.depthOfField.settings = dof;
    76.    
    77.                 yield return null;
    78.             }
    79.    
    80.             playerAnimator.enabled = false;
    81.             dephOfFieldFinished = true;
    82.             depthOfFieldRoutineRef = null;
    83.         }*/
    84.     }
    85.  

    The bottom code is my old script when using postprocessing v1 now I want to do the same with my old code but with postprocessing v2

    I'm getting error on the line :

    Code (csharp):
    1.  
    2.     postProcessVolume.profile.TryGetSettings(out depthOfField);
    3.  
    On the TryGetSettings and the error is :

    The type 'PostprocessingEffects' cannot be used as type parameter 'T' in the generic type or method 'PostProcessProfile.TryGetSettings<T>(out T)'. There is no implicit reference conversion from 'PostprocessingEffects' to 'UnityEngine.Rendering.PostProcessing.PostProcessEffectSettings'.

    How can I fix this error and how can I use it with my old code ?
     
    scionious likes this.
  2. scionious

    scionious

    Joined:
    Sep 26, 2012
    Posts:
    3
    I'm also trying to do the same and getting the same error.
     
  3. DezBoyle

    DezBoyle

    Joined:
    Feb 10, 2013
    Posts:
    5
    Pretty sure you need to include the type that you're trying to get.
    x
    Code (CSharp):
    1. postProcessVolume.profile.TryGetSettings<DepthOfField>(out depthOfField);
    Replace DepthOfField with the class name of the image effect. I'm just guessing its called that