Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Link colors across multiple sprite renderes

Discussion in '2D' started by Kellyrayj, Jul 31, 2014.

  1. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    933
    My characters are made up of a number of different sprites and sprite renderers. (Head, body, arms, legs, ect)

    I'm not really sure what words I need to be using to ask this but here it goes. Is there a way to link a set of sprite renderers so that when I change the color of one sprite, the rest of the sprites for that object are updated as well?
     
  2. Vitor_r

    Vitor_r

    Joined:
    May 23, 2013
    Posts:
    93
    I don't know of an 'automatic' way of doing that.

    If all the body parts use the same Material you can change the material color.
    But as you are using Sprite Renderers and probably using the default sprite material, this will cause all the sprites to change color.

    Using individual Materials for each character will affect your batching... affect a lot :)

    I would make an script that will search and store all the SpriteRenderers of a character in Awake() or Start(). And when you need to change the sprite colors you can iterate the list and change it.

    But i'm just a beginner, maybe someone has a better solution :D
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Instantiate a material, assign it to the appropriate sprites using SpriteRenderer.sharedMaterial, and change the instantiated material's color.

    --Eric
     
  4. Vitor_r

    Vitor_r

    Joined:
    May 23, 2013
    Posts:
    93
    Changing the material of a sprite will make it dont batch, that's correct right?

    I agree with you if he want to do this only with the main character, but i think that he wants to do this with other characters too, that will have 'shared sprites'.
     
  5. Kellyrayj

    Kellyrayj

    Joined:
    Aug 29, 2011
    Posts:
    933
    Thanks Eric! Instantiate was the word I think I was looking for. I will try this and report back on the batching!