Animation to fade alpha but retain color

Is it possible to use an animation to fade the alpha channel on a material without affecting the colours?

I can remove the properties for R G B but as soon as I remove the A, the entire color property is removed.

I want to use this animation to fade out multiple objects of different colours, but they all inherit the colour of the animation.

I could do this via script, but was wondering if there is a way to do this using animation.

It appears that the animation cannot modify the existing color, it creates a new color and applies it to the object.

I decided to use a coroutine to fade out the alpha instead. Here’s the code I used if anyone stumbles across this problem.

StartCoroutine( FadeAlphaRoutine() ); // Add this line in some other function e.g. Start()
IEnumerator FadeAlphaRoutine ()
{
    float duration = 1f;
    float startTime = Time.time;
    MeshRenderer[] renderers = gameObject.GetComponentsInChildren<MeshRenderer>();
    while (Time.time < startTime + duration)
    {
        foreach (MeshRenderer rend in renderers)
        {
            Color clr = rend.material.color;
            Color newColor = new Color(clr.r, clr.g, clr.b, clr.a - (Time.deltaTime / duration));
            rend.material.SetColor("_Color", newColor);
        }
        yield return null;
    }
}

If you are using the Animator component, just animate the color.a value without affecting the r, g, b values.

If you’re using a custom shader, you might be able to add your own extra Vector1 property and just animate that instead

You may try this:

In the Animation window, in the line where you change the Sprite Renderer Color property (if you’re using Sprites), expand the property, and click on the small icon on the right of the rgb lines → Remove Property.

I think it should solve the issue.

No it doesn’t, the problem is that you can’t remove all R, G, B properties and keep only A. Unity is deleting the key when not at least one of the R, G, B property is kept :frowning: