x


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?

more ▼

asked Jul 06 '10 at 10:20 PM

Ony gravatar image

Ony
888 29 36 48

Shouldn't you be using SetColor and GetColor rather than Vector?

Jul 06 '10 at 10:30 PM Eric5h5

I tried those first and had the same results.

Jul 07 '10 at 03:45 AM Ony

Still, you should use Set/GetColor... it's probably safer ;)

Jul 07 '10 at 04:46 AM qJake

I will if I can get either working, lol.

Jul 07 '10 at 05:11 AM Ony

Bump -- I need to change Spec and Emissive color by script and I can't figure it out!!

Jan 16 '11 at 04:04 AM Charles Van Norman
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1655
x814
x507
x78
x1

asked: Jul 06 '10 at 10:20 PM

Seen: 1359 times

Last Updated: Jul 06 '10 at 10:20 PM