Modify Post-Processing Effects Through Code in Unity

Objective: Add and effect when the player pick the speed boost powerup

If you don’t have the post processing game object in your scene I am gonna leave you an article explaining how to create it.

https://rusbenguzman.medium.com/how-to-use-post-processing-in-unity-330decb8c27b

We are gonna add the effect called Chromatic Aberration, this effect creates a distortion that can be used to simulate a super speed in the spaceship. We have to modify the value of the intensity to achieve that look.

Now we have to create a PostProcessing script, use the namespace UnityEngine.Rendering.PostProcessing and declare 2 variables. One to get the reference to the post processing game object and other to get the effect.

Then in the Start method we are gonna get the effect using the function PostProcessVolume.profile.TryGetSettings() and pass the _speedEffect variable as a parameter.

We have to create a public function to modify the intensity value of the _speedEffect variable.

In the player script we have to create a variable and assign the reference to the post processing object. Finally in the coroutine SpeedBoostCooldown we have to call the function to modify the speed effect.

And that’s all! You have a functional code to change post processing effects during the game.

For more information I leave you this link to the post processing documentation:

https://docs.unity3d.com/Packages/com.unity.postprocessing@3.0/manual/Manipulating-the-Stack.html

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rusben Guzman

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.