Search code examples
c#unity-game-engineurp

How to access things in postproccessing from scripts


Hello I have bean making my game and I created a booster for my car and I want to have vignette effect when I step on it, I don't know how to make a script to get the post processing and change the vignette thing. Thanks!


Solution

  • How to get the volume parameters in URP and HDRP are similar to each other, in the following code, after entering the desired volume in the hierarchy, you can carefully see the names of the components mounted on the volume at start.

    using UnityEngine.Rendering;
    using UnityEngine.Rendering.HighDefinition; // .Universal for urp
    
    ///...
    
    public Volume volume;
    
    public void Start()
    {
        volume.profile.components.ForEach(c => Debug.Log(c.GetType().Name)); // displays the volumes components name, for e.g: Fog, HDRISKY, Bloom
    }
    

    Now in the variable change method, all you have to do is get the component via TryGet and change the value.

    if (volume.profile.TryGet(out Vignette vignette)) // for e.g set vignette intensity to .4f
    {
        vignette.intensity.value = .4f;
    }
    

    enter image description here