Search Unity

9 Directional Sprite workflows with either bones, layers or dynamic spritesheets for custom clothing

Discussion in '2D' started by ZolnierGames, Feb 21, 2021.

  1. ZolnierGames

    ZolnierGames

    Joined:
    Feb 19, 2018
    Posts:
    88
    Hey all! I'm jumping into a 2d project and was curious on recommendations to handle 9 directional sprite movement in a 2.5D style environment. I have, say a character and need to be able to add/layer of custom items (think shirts, arms, etc.) that can be assigned at runtime. I have modular sprites designed for the 9 directions so I can use either sprite sheets or bones but my challenge is that I need to combine a custom head with a torso and potentially custom shirts, pants, legs, etc. There may be up to 12 different versions of this similar character on the screen at a given time, each with it's own custom items.

    What is recommended? Is there a way to take a layered sprite sheet approach via perhaps a render texture? Do I just need to premake each sprite layer and then animate each layer separately across all of my sprites? Should I implement bone/skeletal based animation, but how then do I handle the bones when I need to have the character move sideways vs up/down or diagonally?

    Thoughts or suggestions? Thanks all!
     
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Hello @ZolnierGames,
    Seems like you could make good use of 2D Animations SpriteSwap feature. It is a great way to easily swap between different Sprites in your character. The 2D Animation package also comes with a few Samples which demonstrates how this feature can be used. You can find the Samples by going to the Package Manager > and select the 2D Animation package. Once selected, you should be able to see a button to download the samples.

    Let me know how it goes!
     
  3. ZolnierGames

    ZolnierGames

    Joined:
    Feb 19, 2018
    Posts:
    88
    Ted, I appreciate the response but none of those SpriteSwap examples have more than one skeleton or direction. So to expand on the examples, how would you recommend I handle the various directions I need and with up to 12 characters on the screen at once?
     
  4. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    It depends how you would like to animate. If you go the frame-by-frame approach, you could SpriteSwap the individual parts of the character to match your desired direction and customization.

    If you want to use bone based animations, having multiple full characters under the root character GO is probably the best way to go, and then enable the character for the given direction. To add the customization, you can then SpriteSwap the parts of the character that should be switched out.

    To handle 12 characters on the screen at the same time, I take it that you are concerned about the performance? For frame-by-frame animations, the main cost to think about is the size in memory all the SpriteSheets will take. If you have high resolution characters, many frames per animation and/or a lot of customization options always loaded in, it can be quite taxing for your memory budget.
    For 2D Skeletal animations, the main concern is CPU cost when deforming the sprite meshes. Using collections and burst to improve the performance is recommended (See here for more details). Also note that the more vertices the sprite mesh has, the more the CPU cost will be per frame.
    As always, do some performance tests on your target platforms to see how everything performs.
     
    DeanTheodorakis likes this.
  5. ZolnierGames

    ZolnierGames

    Joined:
    Feb 19, 2018
    Posts:
    88
    So, for spritesheets, is there an accepted way to combine/layer spritesheets at runtime? For example. combining the spritesheet for various heads on top of a spritesheet with a body, etc..
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Could you elaborate a bit more on that, @ZolnierGames ? Not quite sure I understand the question