Same animation from multiple spritesheets

Okay, let’s say I have a 2D character that uses a bunch of different animations (walking, jumping, idle) in an animation controller - all dragged out of a spritesheet.

He’s currently in his undies, and needs some layers. I’ve created an identical sprite sheet with just the clothes layer and made sure the frames relate to the original sprite sheet.

Is there a more simple way for me to create a layer on top of the character, that performs the same animation transitions - just from a different sprite sheet?

I could set up animations and animation controllers for every item of clothing, but if I’m separating out legs/bodies/hair/eyes - that’s a lot of animations that all basically do identical things, just on a different spritesheet.

Thanks!

Well, I personally don’t like this solution, but you could put your SpriteSheets into the Resources Folder and than load them by this script:

using UnityEngine;
using System;

public class ReSkinAnimation : MonoBehaviour
{

    public string spriteSheetName;
    void LateUpdate()
    {
        var subSprites = Resources.LoadAll<Sprite>("PlayerSpriteSheets/" + spriteSheetName);
        print(subSprites.Length);

        foreach (var renderer in GetComponentsInChildren<SpriteRenderer>()) {
            string spriteName = renderer.sprite.name;
            var newSprite = Array.Find(subSprites, item => item.name == spriteName);
            if (newSprite) { renderer.sprite = newSprite;}
        }

    }
}

But you have name each sprite exactly the same as in the default spriteSheet…

Here is the video where I have found that solution

So I have edited this script so that you don’t have to rename all your Sprites:

using UnityEngine;
using System;

public class ReSkinAnimation : MonoBehaviour
{   
    [Tooltip("This is the standard SpriteSheet where the script gets its indexes from.")]
    public string defaultSpriteSheetName;
    public string spriteSheetName;

    Sprite[] subSprites;
    Sprite[] defaultSubSprites;

    private void Start()
    {
        subSprites = Resources.LoadAll<Sprite>("Player/PlayerSpriteSheets/" + spriteSheetName);
        defaultSubSprites = Resources.LoadAll<Sprite>("Player/PlayerSpriteSheets/" + defaultSpriteSheetName);
    }
    void LateUpdate()
    {
        foreach (var renderer in GetComponentsInChildren<SpriteRenderer>()) {
            int spriteIndex = Array.IndexOf(defaultSubSprites, renderer.sprite);
            var newSprite = subSprites[spriteIndex];
            if (newSprite) { renderer.sprite = newSprite;}
        }

    }
}

Hopefully they will add a nicer solution for this problem soon…