0
\$\begingroup\$

I need to change the intensity value of my current Vignette effect depending in specific conditions.
So far I haven't been able to achieve this. Please help!

Image of what I want to achieve: enter image description here

My setup:

  • Unity 2019.3.5f1 with URP implemented
  • Post Processing Package (v2) installed
  • Scene with a GameObject + Volume component with Vignette and Bloom effect overrides added
  • A monobehaviour component script in the very same GameObject from above

My monobehaviour script:

using UnityEngine;
 using UnityEngine.Rendering.PostProcessing;

 public class PostProcessingHandler : MonoBehaviour
 {
   private PostProcessVolume _ppv;
   private Vignette _vignette;

   // Vignette intensity values
   [SerializeField, Range(0f, 1f)]
   private float _lowIntensity = 0.25f;
   [SerializeField, Range(0f, 1f)]
   private float _highIntensity = 0.5f;

   private void Start()
   {
     _ppv = GetComponent<PostProcessVolume>();
     Debug.Log(_ppv);
   }
 }

When I try to retrieve PostProcessingVolume component to get it's profile (and further layer manipulation) I always get "null".

Image of my setup: enter image description here

I've seen several guides/posts and even Unity documentation but I cannot get past that starting point of getting the PostProcessingVolume component, what am i missing?

\$\endgroup\$
2
  • \$\begingroup\$ could it be that the component you want to pick is of type 'Volume' and not 'PostProcessVolume'? \$\endgroup\$ Mar 17, 2020 at 1:28
  • \$\begingroup\$ instead of "Debug.Log(GetComponent<PostProcessVolume>());" I tried "Debug.Log(GetComponent<Volume>());". In this last case, Volume is not a valid component type, not even letting me compile correctly. :( \$\endgroup\$
    – Smireles
    Mar 17, 2020 at 8:07

1 Answer 1

3
\$\begingroup\$

It actually has a tricky way to do it. You need to grab the PostProcessValue and then grab the effect that you want to change, in your case the Vignette. After that, you will need to "Override" the values, that is the key. Here is an example I did based on the Unity documentation:

public PostProcessVolume volume; //Assigned with the editor
Vignette vignette; //The post processing effect you want to change

void Start()
{
    vignette= volume.profile.GetSetting<Vignette>(); //Grab the value of the post processing effect

    vignette.smoothness.Override(0.5f); //override the effect that you want with the value you need.
}

As you can see, the "Override" is the key to actually make it work. You can see more in this link.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .