i have an issue with the HDRP, i try to access the focus distance of depth of field parameter added as override on the post processing setting
i want to link the focus distance to a target i already got in my scene
my problem is to acess to the parameter,
using UnityEngine.PostProcessing; is not good anymore
private DepthOfField DOF; this dont work either
i really dont know wich way to acces it, documetation is really unclear about it.
How do you imagine that would work with .PostProcessing, if you see that the things are clearly somewhere under that Volume setup?
As the post-processing is now integrated to HDRP/URP, you need to check their documentation if anything. I donât think thereâs anything in Unityâs ânormalâ docs. Sigh.
But anyway. You do it the same way as you get other volume component type data. First you access the Volume, then get the volume profileâs override you want to modify and change the settings. In your case itâs the DepthOfField. The answers are already posted somewhere here, and I think I also already posted one similar reply.
But itâs best to dig into the source code thatâs available in the package folder and check the API documentation, although in many places it just lists the stuff and really doesnât explain anythingâŠ
Well, you need to write a small script to access the volume component. Tell me what you need help with.
EDIT: Check the thread I posted some tips to earlier: Itâs exact same approach you need to use.
You access the volume component, access the specific effect (DOF) and then change itâs values.
Hereâs a small example, I wrote it so that itâs closer to what you need. You need to also define the fields in your script, and use correct name spaces (HDPipeline and UnityEngine.Rendering and maybe some others.)
Then, in your update, you would calculate the distance you want to use (or any other parameter) and apply it back to the volumeâs effect. You do it like this:
The type 'UnityEngine.Rendering.PostProcessing.DepthOfField' cannot be used as type parameter 'T' in the generic type or method 'VolumeProfile.TryGet<T>(out T)'. There is no implicit reference conversion from 'UnityEngine.Rendering.PostProcessing.DepthOfField' to 'UnityEngine.Rendering.VolumeComponent'.
@liccardi that volume component access should still be same as it was. I just tested that on Unity 2021.1 since the last time I replied I used 2019.x. Anyway, at least I could get the volume and change values. Can you perhaps provide more information?
Is there a Volume assigned to a field in Inspector or have you assigned a Volume component in some other way to your script so that you can actually access it?
if I try to log in it gives me this error: The type âUnityEngine.Rendering.PostProcessing.DepthOfFieldâ cannot be used as type parameter âTâ in the generic type or method âVolumeProfile.TryGet(out T)â. There is no implicit reference conversion from âUnityEngine.Rendering.PostProcessing.DepthOfFieldâ to âUnityEngine.Rendering.VolumeComponentâ.
done, but it conflicts with âusing UnityEngine.Rendering.PostProcessing;â
and if I remove " using UnityEngine.Rendering.PostProcessing; "
gives me an error for this line âvolumeâ.
I got the same issue, and tried all the possible setting I could find it.
But still give me the error message:
he type âUnityEngine.Rendering.PostProcessing.DepthOfFieldâ cannot be used as typeâŠ
Even tried the Unity manual for volume scripting api and the error persist.
Is there something I`m missing? beside ânamespaceâ, âtrygetâ, declaring volume and profile as in example above?
Some hidden setting to make it global or something?