Animate transparency changes without affecting color
January 4th, 2023
In Unity, you can always set transparency for your sprites with the Sprite.color property by setting it with another value.
However, during an animation, you may want to have your sprite color and alpha channel independent. In Pyramidal Break, the final boss shows up as a shadow until you beat them. Only after that you will know their true form. This worked fine with a simple Sprite.Color change inside the code depending if the player had already beaten the boss or not.
However, this particular character has special traits to their animations. With the Idle Animation, the boss will not move but start to disappear with a transparency and opacity changing effect. Without noticing, this trait prevented the "shadow" effect to be used. The variables were correct and the sprite.color change was correctly set to pitch black.
Simple, the transparency variation during the idle animation was setting (and overriding after that) the full color channels during the animation, having the transparency change during the animation and being set to 100% opaque during the rest of animations, but, without considering the other channels independently, we were setting the RGB colors to 100% (full sprite fidelity) as well. By removing the RGB channels on the animator changes timeline, we only changed the transparency and it worked flawlessly.
Don't forget to take this in consideration whenever using transparency inside your animations.
Pyramidal Break developer at Dinamic Creates.