Adding sprites to same layer as bone in 2D animation rig
I am using the 2D Animation package in Unity 2018.3. I have imported a character with a body, arms, and legs and added a basic skeleton rig in the Sprite Editor -> Skinning menu. Each arm has 2 bones and each leg has 2 bones. The rig works great, animations adjust the sprite to move fluidly and all is well. Now I am trying to add armor and weapons to this character. One issue is when adding another sprite as a child of the bone for that area, the sprite does not keep the "Order in Layer" of the bone. For example, one arm is behind the body but in front of the legs. The child sprite can only be either behind both the body and legs, or in front of both body and legs. This i assume is due to the bone Order in Layer being separate from the actual GameObject sprite. Another issue is when adding sprites, they of course do not inherit the mesh nodes from the rig, so they do not bend with the arms or legs.
A possible solution is to have a completely separate character sprite with the armor or weapon drawn on it already, then just swap it out. But this would mean creating and importing a whole new character for every possible combination of armor and weapons! Also, would the new sprite inherit the bones and animations? Surely there is a better solution that I just can't see.
Answer by NotEth4n · Apr 11, 2019 at 08:37 PM
I managed to get this working, though not exactly in the way that I was looking for in my original post. It is important to note that the Arms and Legs were separate from the body, but all on the same imported PNG file. To set up the character sprite, instead of leaving it as Sprite Mode->Single, I set it to Multiple. Then in the sprite editor, I sliced it into each piece (each arm, leg, and the body). Then under the Skinning Menu in the sprite editor, I selected each piece and added bones to that piece as necessary. For example: I double clicked the Left Arm sprite and then clicked add bone and added the arm bones. Then when I double clicked the Right Arm sprite, the bones on the Left Arm disappeared. I went through this process for each piece of the character. After applying the changes and exiting the sprite editor, there were several sprites in the hierarchy under the imported PNG file. After dragging those into the scene, I added a Sprite Skin component to each and pressed Create Bones. Then I set each piece to a different Order in Layer. The difference between this and the original goal is that there are several "Sprite Skin" components, one for each sprite instead of one sprite and one component with all the bones. This method allows me to add new sprites as children of the character sprites and set their Order In Layer to be in front of or behind the other sprites. This works because the Order In Layer for the added sprites is the same Order In Layer as the character sprites.
This only works if the rigged character can be split into multiple pieces.
Your answer
Follow this Question
Related Questions
Transitioning between 2D animations by frame 2 Answers
Unity 2D bones un-binding after closing 1 Answer
2D Outline Shader working in Node Preview But not when rendering 0 Answers
Multiple Sprite Pivot Points 0 Answers
[2D] Updating PSB I had previously rigged and animated BREAKS entire rig 0 Answers