1
\$\begingroup\$

Let's say I have a character and certain things (shoes, vest, hat, etc.) can be changed (visually, just the color changes).

What came to my mind was creating each of them as a separate sprite and then using the appropriate one at a time. but this makes a LOT of sprites (considering animations too) and wastes a lot of my time just repainting them manually.

After that, I thought about changing pixels (my game is in pixel-art style) with a certain color with another color (like changing all #563125 to #137426) but I have no idea how to do this and if I did, how to save the new sprites instead of the old ones (sprites are in .psd format)

So my question is: How can I do this in Unity?

\$\endgroup\$
1
  • \$\begingroup\$ Have you seen that there is a color option on a sprite? \$\endgroup\$
    – Zibelas
    Mar 24, 2022 at 13:47

1 Answer 1

1
\$\begingroup\$

When you want to build a 2d character from multiple sub-sprites, then you might want to look into the 2d animation package. It allows you to create a rig for a 2d sprite which allows to move sub-sprites via the animation system and even deform sprites. This can greatly reduce the number of individual frames you need to draw. It also comes with a SpriteSwap feature which allows you to exchange individual sub-sprites while still using the same rig with the same animations.

Regarding recoloring sprites: Unity can change how a sprite is rendered through the shader assigned to the material assigned to the corresponding SpriteRenderer.

Note that the sprite renderer has a "Color" property, which you can set in the inspector or via script.

The SpriteRenderer communicates this color to the pixel shader via the vertex colors. The shader of the default sprite material already makes use of this information to implement some simple color tinting. So you might be able to do what you want to do by simply changing the color property of the SpriteRenderer.

However, when you want a more advanced coloring effect, like say only recolor parts of the sprite or use a different recoloring algorithm, you will have to look deeper into programming your own sprite shader. When you need any help with this, feel free to open a new question.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the answer! I currently don't have access to Unity but will test your solution later \$\endgroup\$
    – Arian_ki
    Mar 25, 2022 at 1:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .