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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Volume Script - Controll Post Processing via script

Discussion in 'High Definition Render Pipeline' started by V_endeta, Sep 19, 2019.

  1. V_endeta

    V_endeta

    Joined:
    Mar 31, 2017
    Posts:
    28
    I am trying to control the variables of post-processing (ColorAdjustments) via script (Volume Script). The problem is that the variable itself changes but the effect is not seen in the scene... I tried with other components like LensDistortion and Vignette and the same problem occurs. The intensity changes but they are not noticed in the scene (Game View).
    Unity: 2019.3.0b3
     
  2. Skitto

    Skitto

    Joined:
    Jun 3, 2017
    Posts:
    19
    Instead of editing the components directly, maybe try having two separate volumes. Have one that has higher priority, but starts at 0 weight. When you want to apply the changes to post processing, increase the weight of the higher priority volume.
     
    V_endeta likes this.
  3. V_endeta

    V_endeta

    Joined:
    Mar 31, 2017
    Posts:
    28
    Thank you!! This working fine and it's much easier and more optimized.
     
  4. Dreamback

    Dreamback

    Joined:
    Jul 29, 2016
    Posts:
    220
    I can't even access the volume via scripting - if I try to declare "Volume thing;" it doesn't know what Volume is (type or namespace could not be found), though I am using UnityEngine.Rendering; And Visual Studio's autocomplete for UnityEngine.Rendering doesn't have "Volume" as an option. Any idea what I'm missing?

    Edit: figured it out, our code is in a package, so to access Volume we had to add its package to our runtime assembly.
     
    Last edited: Sep 24, 2019
  5. Fopull

    Fopull

    Joined:
    Apr 24, 2020
    Posts:
    1
    how do you add the package to the runtime assembly
     
    fct509 likes this.
  6. fct509

    fct509

    Joined:
    Aug 15, 2018
    Posts:
    108
    I also would like to know how to add the package to the runtime assembly.
     
  7. absurdnoize

    absurdnoize

    Joined:
    Nov 23, 2019
    Posts:
    10
    Okay lads, here how you solve this one:

    add this namespace (assuming you are using URP)
    using UnityEngine.Rendering.Universal;
    class YourClass : MonoBehaviour
    {
    [SerializeField] private UnityEngine.Rendering.Volume volume; <= assign ur volume component here in inspector

    void YourMethod()
    {
    volume.weight = (any value from 0 to 1);
    }
    }

    you are welcome :)
     
    krak- and MassimoFrancesco like this.
  8. MassimoFrancesco

    MassimoFrancesco

    Joined:
    Jul 6, 2019
    Posts:
    44
    Thank you so much!!

    But I must wonder, PP is out now for years. And to this date, something simple as that is still NOT explained in the Unity documentations.
     
  9. BumbleByte

    BumbleByte

    Joined:
    Sep 3, 2016
    Posts:
    8
    In URP 10.2.2 the class Volume is part of the Unity.RenderPipelines.Core.Runtime assembly.
     
    awlok likes this.
  10. absurdnoize

    absurdnoize

    Joined:
    Nov 23, 2019
    Posts:
    10
    Yes, newer versions don't require that library anymore
     
  11. loconeko73

    loconeko73

    Joined:
    Aug 13, 2020
    Posts:
    17
    Thanks ! I was trying to do some nice effects when my player leaves the game area and a PostProcessing volume with a script-controlled weight was perfect for that :)