Hello, I am a complete newbie to Unity (and C#) and I am trying to change an Instance’s Sprite Color palette. I was able to change the color palette of an Sprite (I have attached an example) but since it changes the color of the sprite iself, all instances that use the same sprite also change colors(You even have to re-import the asset if you want to recover the original colors!).
Could somebody please direct me in the right direction? Thank you very much.
Make sure you’re targeting the sprite renderer of the actual sprite you want to modify.
eg: If you throw the following code into your Start function it will change the sprites color to red.
Thank you for the tip UnityLover, it is handy. But I am not changing the color property of the SpriteRenderer I am changing the pixels colors of the sprites with getPixels32 and setPixels32, and since all instances are supposed to use the same sprite, all of them change to the same color.
If you create two instances of the character prefab, and you change the array of new colors in one of them you will see what I mean.
I would like some help to dynamically create and set the recolored sprites… or if anybody has a better idea to achive the same result of the sample I would be very happy to hear it.
Hey
Wanted to check if u had any progress with the spritrrenderer with regards changing color. Im trying to have a sequence where the whole scene in black and white, where thr player passes the spritrs change from black and white to their original color. Would be cool to have this work per-pixel for a nice transition effect
I think I have exactly what you need!. I took a total different approach. I found a shader where you can change the HUE, SATURATION and VALUE of any sprite Renderer.
For you, tweening the Saturation from 0 to 1 will give the desired effect. Just create a Material that uses the shader I am attaching. And then set the Material to the sprite you want to recolor/decolor and you are good to go. (For recoloring what I do is shift the HUE instead of the saturation, and the recoloring looks great).
The shader was not made by me, it was given away in a forum by a fellow game dev.
If you have any questions on how to use it, ask me and I show you.
Hello, I’m trying to achieve recoloring of characters for my game. This looks like it’s working but I only need to change colors of specific areas, our artist have assigned them magenta colors. How could I target this as the only ones that need to change value?
Since I don’t do frame by frame animation I have splitted the graphics that need different coloring in different sprites. I understund it is probably not the most elegant solution thought:
On the other hand I found an asset named **2DxFX **that let you pick a color range and change it’s color (Along other cool features) but have not tryed it myself.
you will need a lynda.com account tho.
This is excellent for games where you want to get some variations on reused sprites, characters, enemies, etc.
You can even create an in game customizer for your character, if you wanted to, following this tutorial