How to change post-processing behaviour of a camera through script?

I have two post-processing behaviours with different settings and I would like to swap them when the player dies. Is that possible, and if so, how?

Of course:

// Include the namespace
using UnityEngine.PostProcessing;

// Assign the profile that you want to swap into
public PostProcessingProfile otherProfile;

void Update () {
  // Whatever trigger you want
  if(Input.GetKeyDown(KeyCode.F)) {
    // Assign the profile
    GetComponent<PostProcessingBehaviour>().profile = otherProfile;
   }
 }

Can you just remove your behaviour and add the correct one when your player dies?

When I play in editor and actually use this script, it gets this error:
“NullReferenceException: Object reference not set to an instance of an object”

I’m just dragging these things in from the project folder. Is there another way to assign them?