Search Unity

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

Discussion in 'Scripting' started by SlenderDevUnity, May 6, 2019.

  1. SlenderDevUnity

    SlenderDevUnity

    Joined:
    Dec 10, 2018
    Posts:
    5
    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.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [ExecuteInEditMode]
    4. [AddComponentMenu("Image Effects/Gamma Correction")]
    5. public class GammaCorrectionEffect : ImageEffectBase
    6. {
    7.     public float gamma;
    8.  
    9.     private new void Start()
    10.     {
    11.         base.Start();
    12.         gamma = Mathf.Clamp(SaveManager.GetFloat("Gamma"), 0.5f, 2f);
    13.     }
    14.  
    15.     private void OnRenderImage(RenderTexture source, RenderTexture destination)
    16.     {
    17.         base.material.SetFloat("_Gamma", 1f / gamma);
    18.         Graphics.Blit(source, destination, base.material);
    19.     }
    20. }
    21.  
    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!
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,195
    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?
     
    SlenderDevUnity likes this.