Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

"renderer.material.color" not working

Discussion in 'Scripting' started by angel_m, Jun 3, 2011.

  1. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    I am trying to change the color tint of one sprite in this way:

    sprite.renderer.material.color=Color.red;

    But it is not working and the sprite remains in his original material color (white).
    The shader is the standard particle/alpha blended and when changed the material color in the Inspector it is showed correctly...

    However when I use:

    sprite.renderer.enabled=false

    it does work and the sprite "dissapear" like expected.

    ????

    EDITED.
     
    Last edited: Jun 3, 2011
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    What shader are you using? Only shaders that utilize a property named _Color will do anything.
     
  3. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    The shader is the standard particle/alpha blended and when changed the material color in the Inspector it is showed correctly.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That shader doesn't have a _Color property, which is why "material.color = Color.red" doesn't work, since that's a shortcut for "material.SetColor ("_Color", Color.red)". If you look in the shader, you can see they used _TintColor instead. (Which is a bit arbitrary if you ask me.)

    --Eric
     
  5. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Is there any solution?
    Thanks anyway.
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, as I mentioned, "material.color = Color.red" is a shortcut for "material.SetColor ("_Color", Color.red)". The particle/alpha blended shader uses _TintColor rather than _Color. I'm sure you can figure it out from here. :)

    --Eric
     
  7. angel_m

    angel_m

    Joined:
    Nov 4, 2005
    Posts:
    1,160
    Yes, I had tried that before asking the last time but I forgot to include the quotation marks in "_TintColor" and I got an error, and I thought it was not so easy to fix, Thanks. :)
     
  8. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    I would edit the shader and report a bug. The faster they fix it, the better. Otherwise, it's going to be broken forever.