'Unity PostProcessing - changing color of bloom in code

I can't seem to find a way to easily change the color of the "bloom"-effect in the unity PostProcessing Stack from code. Here's what I've tried, with no effect:

var postProcessVolume = GameObject.FindObjectOfType<UnityEngine.Rendering.PostProcessing.PostProcessVolume>();

UnityEngine.Rendering.PostProcessing.Bloom bloom = postProcessVolume.profile.GetSetting<UnityEngine.Rendering.PostProcessing.Bloom>();

var colorParameter = new UnityEngine.Rendering.PostProcessing.ColorParameter();
colorParameter.value = mainPlayer.GenerateRandomColour();
bloom.color = colorParameter;
bloom.color.value = colorParameter.value;
bloom.enabled.value = true;   

The code compiles and runs fine, but has no visual effect. I have seen a couple of posts about this, including here and
here. I have tried all approaches I was able to find in those links, with no success.

Is there not a simple way to change the color of the "bloom"-effect from within code in Unity?



Solution 1:[1]

Use the Override (value) method:

    Bloom bloom = postProcessVolume.profile.GetSetting<UnityEngine.Rendering.PostProcessing.Bloom>();
    var colorParameter = new UnityEngine.Rendering.PostProcessing.ColorParameter();
    colorParameter.value = Color.red;
    bloom.color.Override(colorParameter);

https://docs.unity3d.com/Packages/[email protected]/manual/Manipulating-the-Stack.html

Solution 2:[2]

Not sure if anyone needs this but i did somethign similar to vignette with URP

private Vignette GetVignette()
{
    for (int i = 0; i < volume.profile.components.Count; i++)
    {
        if(volume.profile.components[i] is Vignette)
        {
            return (Vignette)volume.profile.components[i];
        }
    }
    return null;
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 STALER
Solution 2 Yasha Sholom