Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Resolved Sprite Swap / Resolver Issue for Lots of Haircuts

Discussion in '2D Experimental Preview' started by RealMcCoyGames, Mar 29, 2021.

  1. RealMcCoyGames

    RealMcCoyGames

    Joined:
    Jul 23, 2018
    Posts:
    65
    I've been trying to use the sprite swap to swap out a characters hair cut. I have one original PSB file which has the whole model (arms, head, hair, beard etc). I have animated this character being idle and running using bones.

    Then I have another PSB file (exact same dimensions) which just has 30 different hair cuts, and another with 30 different beards.

    The hair is in the exact same position as the original PSB file, respectively. So if I were to swap short hair with a massive afro, although the sizes are different they are in the correct positions relative to where the head would be in all PSB's

    It's seems like a massive waste to create 60 different PSB files 1 for each hair cut, when all I'm actually going to be using is the hair. The original PSB file with the model already has about 15 parts to it, so makes more sense to just be able to attach the hair to the bone somehow.

    Is this something you are looking into? I can do a video if you need an example of my use case.

    Thanks
     
    Last edited: Mar 29, 2021
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Hello @RealMcCoyGames,
    Let me reiterate your setup and do correct me if I got it wrong.

    You have three .PSBs, one primary .PSB with your full character and two additional .PSBs with different hair sprites and different beard sprites. You are using bone based animations, so each sprite has to be skinned to the correct bone.

    If this is the case, I do not follow why you would need 60 different .PSB files. When swapping one sprite for another, and you are using SpriteSkin, the sprite that you swap to needs to have its mesh generated in the Skinning editor, and skinned to the same bone structure as the sprite that was swapped out. (There is a way to map it to a new bone structure, but that seems to be outside of the scope of your question).

    In Animation 6.0 (For Unity 2021.1), we've introduced a new concept called Skeleton Sharing. With this new feature, you can create a skeleton in your primary .PSB file and then share the skeleton to variant .PSB files. In your case, you can create your main skeleton in the .PSB file containing your main model, and then add the skeleton to the two .PSB files with the beards and the hair styles. Have a look at our sample to see how we set it up in a demo project.

    If your project targets a lower version of 2D Animation, you would have to copy the skeleton from your primary .PSB file and paste it into your two variant .PSB files. You can copy and paste bone (and mesh data) by using the Copy and Paste buttons, located on the top bar in the Skinning editor.

    Once you have the skeleton in your variant .PSB files, all you need to do is first generate the mesh for all the sprites, and then skin the meshes to the bones. Once this is done, you should be able to swap the sprites.

    Let me know if this resolves your issue, or if I misunderstood your issue statement.
     
  3. RealMcCoyGames

    RealMcCoyGames

    Joined:
    Jul 23, 2018
    Posts:
    65
    Hi Ted,

    Thanks for your reply. You are correct about my set up. I will take a look at your sample when I get a chance and get back to you.

    It sounds like I just didn't realise there was another way of doing it. When I copy over my bones from one psb to another I was getting an error that said number of sprites didn't match or something like that.

    Thanks again, appreciate all the hard work you guys put into unity. Love working with it.
     
  4. RealMcCoyGames

    RealMcCoyGames

    Joined:
    Jul 23, 2018
    Posts:
    65
    Going to attach my beards PSB file so you can see what I mean.

    I'm working atm but will try looking at your sample tonight.

    Also if there is a way for me to send my character model privately I can do that as well if you need it.
     
    Last edited: Apr 1, 2021
  5. RealMcCoyGames

    RealMcCoyGames

    Joined:
    Jul 23, 2018
    Posts:
    65
    OK, managed to get it working now. I was copying over the mesh as well as bones and getting an error saying number of sprites didn't match.

    Works perfectly now sorry for wasting your time!

    Thanks for your help.
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Great that you got your issue resolved, and thanks for coming back with the solution to the issue.
    Happy developing!