unity-game-engineurpbloom

How to refrence a URP Bloom effects intensity value in script in Unity2D


I want to change the intensity value of a bloom effect in a script in unity2D using Universal Render Pipeline.

I tried looking in the URP Bloom manuals and even unitys bloom manuals and found no result, i watched some YT tutorials and none explained how to refrence only the intensity value of a Bloom effect in script. Any help would be appriciated!


Solution

  • First obtain a reference to the PostProcessVolume.

    var volume = GetComponent<PostProcessVolume>();
    

    Then try to get the bloom settings from the profile.

    Bloom bloom;
    volume.profile.TryGetSettings(out bloom);
    

    Now you can modify the bloom properties.

    bloom.intensity.value = 0.5f;
    

    For URP

    namespaces

    using UnityEngine.Rendering;
    using UnityEngine.Rendering.Universal;
    

    Volume

    var volume = GetComponent<Volume>();
    

    Bloom component

    volume.profile.TryGet(out Bloom bloom);
    

    Intensity

    bloom.intensity.value = 40;
    

    IMPORTANT NOTE from the author of the question: for this problem the error was due to the GetComponent function trying to get the volume from itself while the volume was in a different game object, to solve this problem the final code on that line was:

    var volume = objectWithVolume.GetComponent<Volume>();