# Change Post Processing Values on runtime.

**URL:** https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646
**Category:** Post-Processing
**Tags:** Post-Processing, Scripting
**Created:** [July 2, 2017, 10:02am UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646 "2017-07-02T10:02:34Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Khazmadu](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Khazmadu](https://discussions.unity.com/u/Khazmadu)
#### Post date: [July 2, 2017, 10:02am UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/1 "2017-07-02T10:02:34Z")

</div>

I want to change the Color Grading values of the Post Processing Profile on Runtime.

At first I tried setting the values of the actual profil:  
profile.colorGrading.settings.basic.contrast = 0;

but that doesn’t work.

So I tried setting it on the behavior it self but that didn’t work as well:  
behavior.GetComponent().model.settings.basic.contrast = 10;

how exactly can I change the Post Processing on runtime?

---

<div class="post-metadata">

### Author: ![Khazmadu](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@Khazmadu](https://discussions.unity.com/u/Khazmadu)
#### Post date: [July 2, 2017, 12:04pm UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/2 "2017-07-02T12:04:24Z")

</div>

I found the solution:

> **[Home](https://github.com/Unity-Technologies/PostProcessing/wiki/)**
>
> Post Processing Stack. Contribute to Unity-Technologies/PostProcessing development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![sarahnorthway](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sarahnorthway/32/44234_2.png) [@sarahnorthway](https://discussions.unity.com/u/sarahnorthway)
#### Post date: [July 30, 2017, 7:13pm UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/3 "2017-07-30T19:13:19Z")

</div>

The solution linked above (replace the profile with an instanced copy OnEnable, then edit that on Update), results in Post Processing Behaviors with null Profiles in Unity 5.6.2p2. It seems to only happen if the camera is inside a prefab, and might have something to do with the way cameras are handled by SteamVR.

My solution is to check every PostProcessingBehaviour on EditorApplication.playmodeStateChanged and set any null profiles I find. Code (must be in an Editor folder):

```csharp
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.PostProcessing;

[InitializeOnLoad]
public class EditorManager {
    static EditorManager() {
        EditorApplication.playmodeStateChanged += FixMissingPostProcessingProfiles;
    }

    static void FixMissingPostProcessingProfiles() {
        PostProcessingBehaviour[] behaviors = Resources.FindObjectsOfTypeAll<PostProcessingBehaviour>();
        foreach (PostProcessingBehaviour behavior in behaviors) {
            if (behavior.profile == null) {
                Debug.LogWarning("PostProcessingProfile disconnected, reconnecting " + behavior.GetPath());
                behavior.profile = Resources.Load("MyPostProcess") as PostProcessingProfile;
            }
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![mudabbirali92](https://avatars.discourse-cdn.com/v4/letter/m/3be4f8/32.png) [@mudabbirali92](https://discussions.unity.com/u/mudabbirali92)
#### Post date: [August 10, 2019, 12:52pm UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/4 "2019-08-10T12:52:12Z")

</div>

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing;
public class BlurryEffect : MonoBehaviour
{
    //remember to drag and drop your scriptable object into this field in the inspector...
    public PostProcessingProfile ppProfile;
    public float changeValue;
    void Update()
    {
        ChangeDepthOfFieldAtRuntime(changeValue);
        ppProfile.depthOfField.enabled = true;
     
    }
    void ChangeDepthOfFieldAtRuntime( float val)
    {
        //copy current "depth of field" settings from the profile into a temporary variable
         DepthOfFieldModel.Settings deaptoffieldSettings = ppProfile.depthOfField.settings;
        deaptoffieldSettings.aperture += Time.deltaTime * val;
        //set the "depth of field" settings in the actual profile to the temp settings with the changed value
        ppProfile.depthOfField.settings = deaptoffieldSettings;
    }
 
}

}

```

Thank me later 🙂

---

<div class="post-metadata">

### Author: ![yassine14](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/yassine14/32/267975_2.png) [@yassine14](https://discussions.unity.com/u/yassine14)
#### Post date: [August 29, 2019, 6:13pm UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/5 "2019-08-29T18:13:51Z")

</div>

> [@mudabbirali92](#):
>
> ```csharp
> using System.Collections;
> using System.Collections.Generic;
> using UnityEngine;
> using UnityEngine.PostProcessing;
> public class BlurryEffect : MonoBehaviour
> {
> //remember to drag and drop your scriptable object into this field in the inspector...
> public PostProcessingProfile ppProfile;
> public float changeValue;
> void Update()
> {
> ChangeDepthOfFieldAtRuntime(changeValue);
> ppProfile.depthOfField.enabled = true;
>     
> }
> void ChangeDepthOfFieldAtRuntime( float val)
> {
> //copy current "depth of field" settings from the profile into a temporary variable
> DepthOfFieldModel.Settings deaptoffieldSettings = ppProfile.depthOfField.settings;
> deaptoffieldSettings.aperture += Time.deltaTime * val;
> //set the "depth of field" settings in the actual profile to the temp settings with the changed value
> ppProfile.depthOfField.settings = deaptoffieldSettings;
> }
>  
> }
> 
> }
> 
> ```
> 
> Thank me later 🙂

thank you so much i had to make some small changes but overrall it worked perfectly

---

<div class="post-metadata">

### Author: ![sacb0y](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sacb0y/32/101976_2.png) [@sacb0y](https://discussions.unity.com/u/sacb0y)
#### Post date: [June 4, 2020, 10:31am UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/6 "2020-06-04T10:31:46Z")

</div>

Sadly this doesn’t work for PPSV2 😕

---

<div class="post-metadata">

### Author: ![Llama\_w\_2Ls](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@Llama\_w\_2Ls](https://discussions.unity.com/u/Llama_w_2Ls)
#### Post date: [July 6, 2020, 5:40pm UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/7 "2020-07-06T17:40:50Z")

</div>

I’m possibly using the most recent version of the post processing package - July 2020:  
I’ve found a way to edit the settings of your post process volume, and any effects inside of it. None of the answers above were working for me, since unity removed BloomModel.settings from the newest stack and other issues, so I was able to come up with a script that is able to lower the intensity of your bloom by calling the function whenever i press a button.  
using UnityEngine;  
using UnityEngine.Rendering.PostProcessing;  
public class BloomSettings : MonoBehaviour  
{  
public PostProcessVolume volume;  
public void ChangeBloomSettings()  
{  
Bloom bloom;  
volume.profile.TryGetSettings(out bloom);  
bloom.intensity.value = 5f;  
Debug.Log(“Working…”);  
}  
}  
Make sure that you reference the post process volume in the inspector. Thanks to all the answers above for assisting!

---

<div class="post-metadata">

### Author: ![sarahnorthway](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sarahnorthway/32/44234_2.png) [@sarahnorthway](https://discussions.unity.com/u/sarahnorthway)
#### Post date: [November 10, 2020, 12:39am UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/8 "2020-11-10T00:39:34Z")

</div>

I’m back with the new version (Nov 2020) and this time I needed post process effects that fade in over a few seconds.

PostProcessVolume.weight works (most of the time) if you want to fade in ALL the effects, but if you only want to change one, here’s how I do that, by using the original shared profile as the “max” value, 0 as the “min”, then using that to change the instanced profile as percent goes from 0 to 1:

```csharp
private void SetEffectAlpha<T>(float percent) where T : PostProcessEffectSettings {
   volume.sharedProfile.TryGetSettings(out T effectShared);
   volume.profile.TryGetSettings(out T effectInstance);
   if (effectShared == null || effectInstance == null) {
      Debug.LogError("BackgroundEffects failed to get effect, " + typeof(T) + ", " + volume.sharedProfile?.name);
      return;
   }

   switch (effectShared) {
      case Bloom bloomShared when effectInstance is Bloom bloomInstance:
         bloomInstance.intensity.value = bloomShared.intensity.value * percent;
         break;
      case Ripples ripplesShared when effectInstance is Ripples ripplesInstance:
         ripplesInstance.strength.value = ripplesShared.strength.value * percent;
         break;
      case RadialBlur radialShared when effectInstance is RadialBlur radialInstance:
         radialInstance.amount.value = radialShared.amount.value * percent;
         break;
      case ColorSplit splitShared when effectInstance is ColorSplit splitInstance:
         splitInstance.offset.value = splitShared.offset.value * percent;
         break;
      default:
         Debug.LogError("BackgroundEffects unknown effect, " + typeof(T) + ", " + volume.sharedProfile?.name);
         break;
   }
 
   Debug.Log("=== SetEffectAlpha " + typeof(T) + ", " + percent);
}

```

This uses effects from a plugin (SC Post Effects) but just add a case for whatever effect you need to change the “intensity”, “strength”, “amount”, “offset”, “alpha” or whatever the heck variable can be dialed down to 0 to hide the effect.

---

<div class="post-metadata">

### Author: ![sarahnorthway](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sarahnorthway/32/44234_2.png) [@sarahnorthway](https://discussions.unity.com/u/sarahnorthway)
#### Post date: [November 10, 2020, 1:34am UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/9 "2020-11-10T01:34:18Z")

</div>

Another fine rigamarole: if you need to change a PostProcessVolume’s entire profile at runtime, you should apparently do:

```csharp
RuntimeUtilities.DestroyProfile(volume.profile, true);
volume.sharedProfile = newProfile;
volume.profile = null;
PostProcessProfile junk = volume.profile;

```

First line prevents a memory leak.

Last two lines replace volume.profile with an instanced copy of the sharedProfile, which you can edit at runtime without screwing up the original one in your file system.

Would love to know any simpler way to switch profiles or fade a full stack of PostProcess effects in and out as my solutions feel convoluted but I could not find a better way.

---

<div class="post-metadata">

### Author: ![sacb0y](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/sacb0y/32/101976_2.png) [@sacb0y](https://discussions.unity.com/u/sacb0y)
#### Post date: [November 10, 2020, 3:00am UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/10 "2020-11-10T03:00:34Z")

</div>

I brought this up in another thread about how this system deals with priority and global volumes in the context of cinemachine.

They really need to add a better way to manage these things.  
[Feedback - Post process stack integration flaw with priority, toggling effects - Unity Forum](https://discussions.unity.com/t/794414)

---

<div class="post-metadata">

### Author: ![YashaISR](https://avatars.discourse-cdn.com/v4/letter/y/b9bd4f/32.png) [@YashaISR](https://discussions.unity.com/u/YashaISR)
#### Post date: [March 20, 2022, 11:40pm UTC](https://discussions.unity.com/t/change-post-processing-values-on-runtime/669646/11 "2022-03-20T23:40:23Z")

</div>

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 _is Vignette)_  
_{_  
_return (Vignette)volume.profile.components\*;\*_  
_}_  
_}_  
_return null;_  
_}_
