Search Unity

i can't change the intensity of chromatic aberration

Discussion in 'Image Effects' started by vidanov, May 24, 2022.

  1. vidanov

    vidanov

    Joined:
    Jan 31, 2022
    Posts:
    2
    I am trying to change the intensity of chromatic aberration. I've looked at a ton of guides and can't seem to figure out what I'm doing wrong.

    fixing the error is not so important for me as understanding how to change the intensity using a script.

    here is my script

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering.PostProcessing;
    5.  
    6. public class postprocessing : MonoBehaviour
    7. {
    8.     private PostProcessVolume pv;
    9.     private ChromaticAberration ca;
    10.  
    11.  
    12.     void Start()
    13.     {
    14.         pv = GetComponent<PostProcessVolume>();
    15.         pv.profile.TryGetSettings(out ca);
    16.     }
    17.  
    18.  
    19.     public void ChromaticAberrationOnOff(bool on)
    20.     {
    21.         if (on)
    22.         {
    23.             ca.active = true;
    24.         }
    25.         else
    26.         {
    27.             ca.active = false;
    28.         }
    29.     }
    30. }
    31.  
    here is the error -
    NullReferenceException: Object reference not set to an instance of an object
    postprocessing.Start ()
     
  2. vidanov

    vidanov

    Joined:
    Jan 31, 2022
    Posts:
    2
    Sorry for creating a useless thread. It was necessary to delete everything and write again exactly the same script. And everything worked.