Accessing PostProcessing Profile Settings from script URP error. 2020.2.7
(2020.2.7)(URP) I'm trying to make a dynamic depth of field effect. I have not imported any postprocessing assets from the package manager instead im using the global volume component on an empty game object. I have a volume profile linked to it which has a depth of field override which is set to the bokeh mode. I made a new script and attached it to the camera
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
public class DepthOfField : MonoBehaviour
{
DepthOfField comp;
public Volume volume;
void Start()
{
volume = gameObject.GetComponent<Volume>();
volume.profile.TryGet<DepthOfField>(out comp);
}
}
I get an error on
Which saysvolume.profile.TryGet(out comp);
The type 'DepthOfField' cannot be used as a type parameter 'T' in the generic type or method 'VolumeProfile.TryGet(out T)'. There is no implicit reference conversion from 'DepthOfField' to 'UnityEngine.Rendering.VolumeComponent'.
Please Help!
Answer by hunternance93 · Mar 14, 2021 at 04:15 AM
Your class is named DepthOfField, so when you have local variable DepthOfField comp it is of type of the class it is in (DepthOfField) not of type UnityEngine.Rendering.Universal.DepthOfField
By the way, if anyone runs into this issue and this was not their cause, check to see if you have
using UnityEngine.Rendering.PostProcessing;
instead of
using UnityEngine.Rendering.Universal;
as that was my issue.
Your answer
Follow this Question
Related Questions
2019.3 URP - Post Processing not working (Volumes) 15 Answers
How to use Post-Processing with URP in a 2D project? 0 Answers
Exclude UI / HUD layer from post processing in Universal RP using 2D Renderer 0 Answers
Lift, gamma, gain Android colours completely wrong. 1 Answer
Setting Lift-Gamma-Gain values from C# script? (URP, Post-Processing v2) 1 Answer