Changing Animation Clip Sprite Using Script

Hey, i was wondering how i would go about changing the sprite within an animation clip but keeping the transform keyframes etc. I have an upgrade system using scriptable objects and they hole the Sprite for each upgrade level. I was wondering how i would get a sprite to be replaced by one from one of them.

Ok so i’ve now done it so i have some animation overide controller in a array within the Scriptable Object. I try to make the animator controller equal to one of the ones in the Scriptable object but i get this error

CS0029: Cannot implicitly convert type ‘UnityEngine.Animator[ ]’ to ‘UnityEngine.Animator’

The easiest way is to not animate the sprite, only the transforms, colors, game object active etc. Then you can use a script to change the sprite based on your upgrade level. Note that you cannot touch the sprite reference in the animation, otherwise you won’t be able to change it from script once the animation is running.

Another option would be to use a script as indirection: Add a sprite reference field on the script and animate it instead of the sprite renderer. The script then sets the sprite on the renderer and you can add the logic to swap out the sprite based on some dynamic factors.

In the editor you can use AnimationUtility to update clips dynamically but it’s not available in builds. You could maybe do something with Playables but the documentation is sparse and Unity has let it languish for a long time.

thank you so much that just saved me a whole lot of time i didnt know if you got rid of the sprite in the animation clip it would just take it from the sprite of the gameobject