The question was posted a while ago but since I came accross this issue and found my own solution I thought I’d post it here for any one who needs it.
Below is a pretty simple system that will allow you to reuse the same animation sets with different sprite sheets. What you do is drag and drop all the sprite of the sprite sheet in the same order into the sprites array. Then while animating use animation events and call SetSprite using the index of the sprite in the array.
Some notes on this is, from testing it seems to only work in play mode. Also if you have a single frame animation you need make the animation event happen after frame 0 of the animation as it might skip that one for some reason. Other than that it’s a pretty simple solution that should save quite you a bit of work.
using System.Collections;
using UnityEngine;
[RequireComponent (typeof(SpriteRenderer))]
public class SpriteSheetAnimator : MonoBehaviour
{
public Sprite[] sprites;
private SpriteRenderer _spriteRenderer;
public SpriteRenderer spriteRenderer {
get {
if (_spriteRenderer == null) {
_spriteRenderer = GetComponent<SpriteRenderer> ();
}
return _spriteRenderer;
}
}
public void SetSprite (int index)
{
Debug.Log ("Call");
if (index < 0 || index >= sprites.Length)
return;
spriteRenderer.sprite = sprites [index];
}
}
I’ve been struggling with this problem for a year or so. The Animator unfortunately was not made to deal with sprite characters with multiple skins, which is something very common when making sprite-based games
In one project, we solved this through having a spritesheet that contained the character in all poses on the left side and then a copy of the same poses, but with another skin, on the right side. We used the animator to animate the character with a default skin and a shader that would offset the pixels in the sprite renderer to determine what skin should be used.
In another project, due to how the spritesheet was being made, we tried another solution, that was closer to Pendatic’s. We are using the animator to “animate” a public int that determines which frame to render, from a list. Everything was fine until we started using the Timeline to make cutscenes. Animating an int instead of a sprite lead to all kinds of problems with interpolation. For example, when sequencing two animations with the Timeline, for a very quick time between these animations, the int slides from the final value in the first animation to the first value in the following animation…
Never thought I would see the same problem I had!!
Thought I had made a really ingenious system where I had a car with different attachments but same basic animation cycle that needed to be seamless, by using an int that is animated, and based on the different bools the car with attachment sprites are used instead. A really good system, but as you said, there were issues. In my case it skipped a lotta frames, and causing some objects that were manually placed on it in Unity to go out of sync all the time. In the end, I had to make all of the sprites seperate GameObjects that are animated using same animation attached to the parent object. Had to do the same thing for each attachment in the animation window tho.