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’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Custom Post Process Bugged?

Discussion in 'High Definition Render Pipeline' started by jister, Feb 8, 2020.

  1. jister


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

    if i get it like this:
    Code (CSharp):
    1. areaFX = FindObjectOfType<DrawArea>();
    the next line:
    Code (CSharp):
    1. areaFX.intensity.value = 0.0f;
    doesn't work?

    if I get it like this:
    Code (CSharp):
    1. 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?
  2. antoinel_unity


    Unity Technologies

    Jan 7, 2019

    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.
    jister likes this.