don't know how to turn off specific PostProcessVolume effect

Hi! I’m trying to figure out how to get my SettingsMenu script to turn on and off the MotionBlur effect on my Post Processing Volume, however i’m not sure what to do and after trying out in-game it doesn’t seem to toggle it on or off when I inspect the volume, and doesn’t give any errors in the console either, could I get some help to figure this out? Thanks!

    public PostProcessVolume volume;
    MotionBlur motionBlurLayer;
    public Toggle MBlurToggle;

    public void Update()
    {
        if (MBlurToggle.isOn == true)
        {
            PlayerPrefs.SetInt("MBtoggle", 0);
            volume.profile.TryGetSettings(out motionBlurLayer);
            motionBlurLayer.active = MBlurToggle;
        }
        else
        {
            PlayerPrefs.SetInt("MBtoggle", 1);
            volume.profile.TryGetSettings(out motionBlurLayer);
            motionBlurLayer.active = MBlurToggle;
        }
    }

The above is ALWAYS true as long as MBlurToggle is pointed at a valid toggle.

The thing you want to assign is the .isOn property.

Also, you have like 100% replicated code there. You want to avoid that.

For one, don’t splatter PlayerPrefs string literals all over your code. Wrap it up like this:

You should also subscribe to the Toggle’s onValueChanged delegate:

Then it just becomes:

  • assign the toggle state to the playerprefs

  • assign the state to the .active property

ALSO: be sure you set things up properly at program start so that the toggle AND the effect matches what is in the playerprefs