saving scene resets shader property

Hi,

I have a shader made in SSE that has 2 different float properties (Intensity and Mod). When I save the scene the “mod” float property always resets to 2. I do not know why. The other float property stays at whatever it is set too.

Why might this be occuring?

Shader "LightControlReflective"
{
	Properties 
	{
_MainTex("Base (RGB) Gloss (A)", 2D) = "white" {}
_Color("Main Color", Color) = (1,1,1,1)
_LightColor("_LightColor", Color) = (1,1,1,1)
_Intensity("_Intensity", Float) = 1.5
_Mod("_Mod", Float) = 2
_Lightmap("_Lightmap", 2D) = "black" {}
_Cube("Reflection Cubemap", Cube) = "black" {}

	}
	
	SubShader 
	{
		Tags
		{
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"

		}

		
Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}


		CGPROGRAM
#pragma surface surf BlinnPhongEditor  vertex:vert
#pragma target 2.0


sampler2D _MainTex;
float4 _Color;
float4 _LightColor;
float _Intensity;
float _Mod;
sampler2D _Lightmap;
samplerCUBE _Cube;

			struct EditorSurfaceOutput {
				half3 Albedo;
				half3 Normal;
				half3 Emission;
				half3 Gloss;
				half Specular;
				half Alpha;
				half4 Custom;
			};
			
			inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
			{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;

			}

			inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
			{
				half3 h = normalize (lightDir + viewDir);
				
				half diff = max (0, dot ( lightDir, s.Normal ));
				
				float nh = max (0, dot (s.Normal, h));
				float spec = pow (nh, s.Specular*128.0);
				
				half4 res;
				res.rgb = _LightColor0.rgb * diff;
				res.w = spec * Luminance (_LightColor0.rgb);
				res *= atten * 2.0;

				return LightingBlinnPhongEditor_PrePass( s, res );
			}
			
			struct Input {
				float4 color : COLOR;
float2 uv_MainTex;
float4 meshUV;
float3 viewDir;

			};

			void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);

o.meshUV.xy = v.texcoord.xy;
o.meshUV.zw = v.texcoord1.xy;

			}
			

			void surf (Input IN, inout EditorSurfaceOutput o) {
				o.Normal = float3(0.0,0.0,1.0);
				o.Alpha = 1.0;
				o.Albedo = 0.0;
				o.Emission = 0.0;
				o.Gloss = 0.0;
				o.Specular = 0.0;
				o.Custom = 0.0;
				
float4 Split0=IN.color;
float4 Assemble0_3_NoInput = float4(0,0,0,0);
float4 Assemble0=float4(float4( Split0.x, Split0.x, Split0.x, Split0.x).x, float4( Split0.y, Split0.y, Split0.y, Split0.y).y, float4( Split0.z, Split0.z, Split0.z, Split0.z).z, Assemble0_3_NoInput.w);
float4 Sampled2D0=tex2D(_MainTex,IN.uv_MainTex.xy);
float4 Multiply0=Sampled2D0 * _Color;
float4 Tex2D0=tex2D(_Lightmap,(IN.meshUV.zwzw).xy);
float4 Multiply8=Tex2D0 * float4( Split0.w, Split0.w, Split0.w, Split0.w);
float4 Multiply2=_Intensity.xxxx * Multiply8;
float4 Multiply1=_LightColor * Multiply2;
float4 Multiply3=Sampled2D0 * Multiply1;
float4 Add0=Multiply0 + Multiply3;
float4 TexCUBE0=texCUBE(_Cube,float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ));
float4 Multiply5=Sampled2D0.aaaa * TexCUBE0;
float4 Multiply6=_LightColor * Multiply5;
float4 Add2=Add0 + Multiply6;
float4 Multiply4=Assemble0 * Add2;
float4 Multiply7=_Mod.xxxx * Multiply4;
float4 Master0_1_NoInput = float4(0,0,1,1);
float4 Master0_2_NoInput = float4(0,0,0,0);
float4 Master0_3_NoInput = float4(0,0,0,0);
float4 Master0_4_NoInput = float4(0,0,0,0);
float4 Master0_5_NoInput = float4(1,1,1,1);
float4 Master0_7_NoInput = float4(0,0,0,0);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Multiply7;

				o.Normal = normalize(o.Normal);
			}
		ENDCG
	}
	Fallback "Diffuse"
}

I dont know why but, I renamed the _Mod property to _Modulate and it works now…

Have the exact same problem now using the latest Unity release. Random float values defaults back to the written value in the shader upon save. Anyone know anything more about this?

Same problem here its driving me nuts.

The code below will only on SOME materials cause the colour data to be lost. Setting the texture or float properties seem to be fine. Only confined to vectors.

Debug.Log("Set Colour on " + targetMat.name);
				targetMat.SetColor("_DarkColour", dark);
				targetMat.SetColor("_MidColour", mid);
				targetMat.SetColor("_LightColour", light);
				EditorUtility.SetDirty(targetMat);
				Debug.Log("Set Colour on "
					+ " -- " + targetMat.name
					+ " -- " + AssetDatabase.GetAssetPath(targetMat)
					+ " -- " + mid
					+ " -- " + targetMat.hideFlags 
					+ " -- " + targetMat.shader.hideFlags);
				
				AssetDatabase.SaveAssets();
				mid = targetMat.GetColor("_MidColour");
				Debug.Log(mid);

I know this is an old thread, but I’m getting the same problem in Unity 5.3.1p3. Also, switching applications and coming back to the editor seems to reset them too.

This happens on materials instances created within the editor at runtime (i.e. through extending the editor) for me.

Did anybody ever figure it out?

Bumping this 7 years later…

instances are disposed of when no longer needed so i figure the garbage collector took your materials away

ie material instances in playmode are destroyed when exiting playmode