Search Unity

Resolved How to change 2D sprites if each frame is separated by one image.

Discussion in '2D' started by aomikki, Jan 27, 2022.

  1. aomikki

    aomikki

    Joined:
    Mar 26, 2018
    Posts:
    7
    I was using this free character pack from the asset store, it has diverse amount of characters and enough animations to try out.

    The problem is that, each animation is separated by one image per frame instead of being a spritesheet. There are six animations per character, per gender, in 30 different models.

    separated frames.PNG

    In total, there would be 60 animator controllers with six of the same animations.

    I feel that it's possible to simplify this into one animator and change the sprite when needed , but how do I exactly change it? Additionally, what would happen if two or more characters are using the same animator but intend to use different models?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    That's a cool little asset, thanks for the link.

    It would be pretty easy to do what you propose, because the 30 heroes are all very uniform as far as what they have (male, female, six anims, the same (or nearly same) frame count, etc.)

    It's mostly an organization problem and it would yield to some clever editor scripting.

    For instance, here's how I would tackle it:

    - make a generic ScriptableObject A that holds all the frames in a single directory
    - make another ScriptableObject B that has all six animations as instances of A
    - for each character:
    ---> make a B
    ---> iterate all six subdirectories and:
    ------> make an A inside each one
    ------> slot the sprites in
    ------> add the reference to the proper slot in the B

    Once you did that you would have 30 heroes, x2 for male / female, and you could make a generic classic oldskool sprite-swapper controller to run it all, flip left/right, etc.
     
  3. aomikki

    aomikki

    Joined:
    Mar 26, 2018
    Posts:
    7
    Hi, sorry for bumping this one up. Just going to say thanks for the great advice! I found that the Unity 2D animation has the similar sprite-swapper and the assets like you have mentioned in experimental. I don't think I could ever find it out without your suggestions.
     
    Kurt-Dekker likes this.