Animation and Sprite-Swapping

Hey everyone.
I’ve combed through the forums and docs, and I’ve seen many questions similar, but I can’t seem to find an efficient way to do this.

So basically, say I have an NPC with a whole heap of animations based on one sprite sheet. Is it possible to use the same animation clips/controller with a different set of sprites?

So far I’ve uncovered two methods of doing this:

  • Replace all sprites in the SpriteRenderer component using Resources.Load in LateUpdate() with sprites of the same name. (Courtesy of Unity lectures video).
  • Use Animation Events to reassign sprites manually through script.

Both of these methods work fine, but the first is very resource-heavy, especially in multiple instances, and the second requires a lot of code on my part (since there will be 50+ animations per NPC), or a large sprite array, which again will be resource-heavy with several instances.
Are there any alternate methods to achieve this, preferably without a lot of overhead?

Also, does anyone know if Unity plans to integrate something like this any time soon? Some of the forum posts are from back in 2010.

I had the exact same problem in my own project and I was able to solve it with an editor tool which works like this:

  1. Read the contents of a user-selected Animator Controller asset
  2. Read and store sprite-related keyframe data (original sprites, frame time) from the Animation Clips which are referenced inside the Animator Controller asset
  3. Find original spritesheet texture assets used in those keyframes
  4. Allow user to select the replacements for those original spritesheet texture assets
  5. Generate a Scriptable Object containing all sprite-related keyframe data with equivalent sprites from user-specified sources for each animation state along with the state hash

The generated Scriptable Object asset can then be used to override the sprites set by the Animator component during runtime by checking the current animation hash and picking out a replacement sprite from the Scriptable Object.

This way you are able to reuse the same Animator Clips and even the Animator Controller for any amount of animated objects which differ only in spritesheet sources.

You can find my solution to this problem here: