- Home /
Can't set _SpecColor but can set _Color no problem - why?
I have an instantiated prefab object with multiple materials assigned. I'm able to easily change properties its instanced material like this:
bodyMesh.renderer.materials[0].SetVector( "_Color", Vector4(1.000, 0.1, 0.1, 1.000) );
and
bodyMesh.renderer.materials[0].mainTexture= theCharTexBundle.assetBundle.Load("BODY-hi-body", Texture2D);
So far, so good. That changes the color and the texture with no trouble.
But... when I try to set the _SpecColor in the same way I'm setting _Color, nothing happens:
bodyMesh.renderer.materials[0].SetVector( "_SpecColor", Vector4(1.000, 0.1, 0.1, 1.000) );
That does nothing.
Why does the _Color property change just fine but _SpecColor doesn't? I feel like I'm missing something obvious.
I'm using the Skin/Bumped Specular shader from the wiki.
Here's the first part of that code:
Shader "Skin/Bumped Specular" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
_BumpMap ("Bump (RGB)", 2D) = "white" {}
_RimTex ("Rim ramp (GRB) Fresnel ramp (A)", 2D) = " grey" {}
_WrapTex ("Wrap ramp (RGBA)", 2D) = "grey" {}
}
The crazy part is that right before I change the SpecColor I have this:
print (bodyMesh.renderer.materials[0].GetVector("_SpecColor"));
and it prints the original color, then I do it again after I change the Spec and it prints the new result that I set. When I look at the object in the inspector or in game the spec color is not changed.
I'm losing my mind perhaps?
Shouldn't you be using SetColor and GetColor rather than Vector?
Still, you should use Set/GetColor... it's probably safer ;)
Bump -- I need to change Spec and Emissive color by script and I can't figure it out!!
Your answer
Follow this Question
Related Questions
Material doesn't have a color property '_Color' 4 Answers
Changing two different objects renderer colour 1 Answer
Mobile\Vertex Colored shader 0 Answers
Material doesn't have property '_Color' 4 Answers
How can I edit a built-in shader ? 1 Answer