Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Paperdoll modular character

Discussion in '2D' started by NullBy7e, Apr 16, 2020.

  1. NullBy7e

    NullBy7e

    Joined:
    Mar 20, 2020
    Posts:
    7
    Hi there!

    I have a paperdoll asset and I'm working on making it modular, I want to be able to create characters with the paperdoll asset as a base and add clothing pieces on the fly (overlayed).

    This is what I got: upload_2020-4-16_20-49-12.png

    On the right side you can select a sprite for each slot, and when you click Generate, it will edit the sprite renderer components on the left side.

    How can I animate the different directions? The asset I use includes animations for all 4 directions and every new outfit or hat etc is made in such a way that you can draw it on top of the character base asset (paperdoll).

    I've read about the sprite asset library and sprite swap assets but I don't see how that can work with a modular design.

    Thanks!
     
  2. NullBy7e

    NullBy7e

    Joined:
    Mar 20, 2020
    Posts:
    7
    Bump :) Am I out of luck?
     
  3. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    This is something I've wondered myself. I don't have an answer, but there is a few pieces that might help:
    First, you can swap animations at run time, you just have to specify the each animation.
    Two, pretty obviously, animations like everything else can be overlapped so you can break them up by piece. So you could animate each head, each hat, each arm, etc.

    Honestly though, that seems pretty nasty and clunky to me for full character customization. You may actually be better off manually coding your animation rather than going through the animator. You would still need to break your character down into pieces and animate each piece, but don't need to go through the extra step of specifying each of these as separate animations then swapping them in and out at run time. Instead you'd just make a scriptable object and toss them into big arrays you reference as needed.

    If you're just doing side on, look into skeletal 2d animation. It might speed things up, although the customization part from what I've seen is still pretty clumsy but I'm not even remotely close to an expert on that so it may actually be pretty easy.
     
  4. NullBy7e

    NullBy7e

    Joined:
    Mar 20, 2020
    Posts:
    7
    Hey, so if I understand correctly, you mean to put each animation clip into a ScriptableObject and then reference this during runtime?

    Is that going to work for different sprites?
     
  5. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    Yes, and yes it will work for different sprites. I used this method myself for a little bit to change my door animations so that they matched the appropriate door. So I had a stone door and a wood door with different graphics for each However, I found this method was very clunky.

    So, basically what you do is you make your animator on the gameobject, then create your animations for each piece that will be controlled by that particular gameobject. So say you have a gameobject in charge of head gear, you'd make animations for Cowboy hat, and baseball cap, and whatever else. For defaulting you'd assign one of these in as the animation is uses for the movement, but you have all the others available, just not hooked up. These you drop into a scriptable object so you can get their references and then at run time you swap the animation in the animator to the actual animation you want. You'd repeat this process making gameobjects for each piece of your character, setting their sorting order so they appropriately overlap to look correct at run time.

    The reason I found this clunky is you can accomplish the same thing without all that overhead of specifying animations just by directly swapping the sprites and dropping the animator entirely. Most walk cycle animations and such aren't complex. You show frame 1 at time index 1, change it to frame 2 at time index 2 and so forth. If the animations were very complex (like you were making a 2D platformer with all kinds of different jump, dash, etc animations this method becomes less practical as you're essentially recoding the animator yourself, but with simple stuff I don't see much benefit of going through the extra hoops)

    For the coding how to do the swapping, I believe this covers it:
    https://answers.unity.com/questions/1319072/how-to-change-animation-clips-of-an-animator-state.html
     
  6. NullBy7e

    NullBy7e

    Joined:
    Mar 20, 2020
    Posts:
    7
    I don't really consider this to be a modular approach as you still have to create animations for each clothing piece? Writing a custom animator is a bit overkill I think, Unity should just support what we want to do. What I have is a sprite sheet for the base character which has: idle, walk and run. For each outfit I have another sprite sheet which is aligned in such a way that it can overlap with the base sprite sheet. Now, what I want to do is adjust each animation clip during run time and change the sprites but I can't seem to find a way.

    So for example for walking to the right I have these sprites (frames):

    Base Character Sprite Sheet
    char_a1_p_1
    char_a1_p_2
    char_a1_p_3
    char_a1_p_4
    char_a1_p_5
    char_a1_p_6

    And then the outfit sprite sheet has the same number of frames at the same position so:
    char_a1_o_1
    char_a1_o_2
    char_a1_o_3
    char_a1_o_4
    char_a1_o_5
    char_a1_o_6

    During run time I want to swap them out:
    char_a1_p_1 -> char_a1_o_1
    char_a1_p_2 -> char_a1_o_2
    char_a1_p_3 -> char_a1_o_3
    char_a1_p_4 -> char_a1_o_4
    char_a1_p_5 -> char_a1_o_5
    char_a1_p_6 -> char_a1_o_6

    Currently, I don't see a way to do this besides animating it with custom code directly.
     
  7. Derekloffin

    Derekloffin

    Joined:
    Mar 14, 2018
    Posts:
    322
    Yeah, as I said, I find it a very clumsy method and pretty much believe right now you're better off just coding your own animation. The animator is great for some stuff, but customization seems to be a place where it really needs work.
     
  8. NullBy7e

    NullBy7e

    Joined:
    Mar 20, 2020
    Posts:
    7
    Bump for sanity, it's 2021 now and I haven't found a solution yet. Besides completely coding the animations myself, the only option is to have a naked protagonist....:oops: