Gamma Correction image effect keeps resetting, doesn't save value?

Hello, everyone. So, I am having a problem with making my Gamma Correction image effect script save a specific value upon restarting the Editor, or even entering Play Mode.

using UnityEngine;

[ExecuteInEditMode]
[AddComponentMenu("Image Effects/Gamma Correction")]
public class GammaCorrectionEffect : ImageEffectBase
{
    public float gamma;

    private new void Start()
    {
        base.Start();
        gamma = Mathf.Clamp(SaveManager.GetFloat("Gamma"), 0.5f, 2f);
    }

    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        base.material.SetFloat("_Gamma", 1f / gamma);
        Graphics.Blit(source, destination, base.material);
    }
}

As stated before, every time I input a custom value in the Inspector, the value stays the same up until I exit or enter Play Mode.

I should note that I am using a legacy version of Unity 4.5.1f3, but interestingly enough, this has the same outcome when upgrading to newer versions (example: Unity 5.2.3).

Can someone please help? If so, it’d be a great help. Thanks in advance!

You’re calling SaveManager.GetFloat' in start, and assigning that value to the property, and you've flagged this script to ExecuteInEditMode’, so it will be running that in the editor. Since it doesn’t look like you ever call SaveManager.SetFloat (assuming that’s a method on this asset), then it sounds like you’re just loading the gamma value using your save manager every time.

Maybe you want to get rid of the SaveManager.GetFloat call?

1 Like