Custom Post Process Bugged?

hey I'm having a real hard time getting a proper reference to a custom PostProcessVolume.

if i get it like this:

areaFX = FindObjectOfType<DrawArea>();

the next line:

areaFX.intensity.value = 0.0f;

doesn't work?

if I get it like this:

FindObjectOfType<Volume>()?.profile?.TryGet(out areaFX);

the intensity = 0 works but the moment i want to set any other values to the shader, the material reference in my postprocess (DrawArea.cs) returns null?

if i never try to set anything in script and just use the inspector, everything works fine?

Anyone else experiencing trouble like this?


Because we use an override system that works by instancing multiple volume components (at least one default and then one per volume instance) the FindObjectOfType function may not return the volume component you expect (even if you have only one volume in your scene).
The way to get the correct component would be to find the volume using GetComponent and then access to the sharedProfile to get the components. We used the same pattern as for materials on meshRenderers where the material property creates a new material instance and assign it to the meshRenderer and the sharedMaterial returns the material asset assigned on the meshRenderer.

Then from the profile, just like in your example you can use TryGet to retrieve your component. Note that when accessing properties you must always use the .value accessor of the property to change it's value like you did in your second sample of code. If you assign directly without using .value, the changes won't be reflected to the component data.

1 Like