- Home /
Modifying postprocessing properties during runtime
I'm attempting to use code to modify the saturation value on my Color Correction Curves script such that as the player gets closer to the object, the colors on screen get more saturated. I can't seem to figure out how to refer to the properties of the scripts in order to set their values though.
using UnityEngine;
using System.Collections;
public class VisualController : MonoBehaviour {
public GameObject Player;
public GameObject musicBox;
float saturationValue;
float bloomThreshold;
void Update() {
saturationValue = 1/Vector3.Magnitude (Player.transform.position - musicBox.transform.position);
print (saturationValue);
bloomThreshold = Vector3.Magnitude (Player.transform.position - musicBox.transform.position);
//print ("bloomThreshold)
}
}
This is what I have so far. How would I go about telling Unity to set the Color Correction Curve's property "Saturation" to the corresponding value?
Answer by Snoopy20111 · Nov 17, 2016 at 08:10 PM
While it's been rather quick, I discovered how to get this done. Hopefully my self-answer helps somebody.
Rather than inheriting class behavior from MonoBehaviour, you have to inherit it from PostEffectsBase, as well as declare that you're in the UnityStandardAssets.ImageEffects namespace. This allows you to access the post processing properties, and also to edit them. So my script that functioned looked something like this:
using UnityEngine;
using System;
namespace UnityStandardAssets.ImageEffects
{
public class VisualController : PostEffectsBase {
public GameObject Player;
public GameObject musicBox;
double saturationValue;
//float bloomThreshold;
void Update () {
saturationValue = Vector3.Magnitude (Player.transform.position - musicBox.transform.position);
print (saturationValue);
//bloomThreshold = Vector3.Magnitude (Player.transform.position - musicBox.transform.position);
gameObject.GetComponent<ColorCorrectionCurves>().saturation = saturationValue;
//gameObject.GetComponent<BloomOptimized>().threshold = bloomThreshold;
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612100839im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to get quality Depth Of Field effect with Post Processing Stack V2? 1 Answer
Why is the negative texel size check necessary when flipping texture coordinates for D3D? 1 Answer
Weird problem with RenderTexture and HDRP Custom Pass 0 Answers
Using Render Texture with Screen Overlay 1 Answer
How to properly use RTHandles in HDRP for post effects 0 Answers