2D sprite swapping/sorting layer changing during animation?

Hey Unity Community,

I’ve been toying about with Unity for a little over a week trying to make a 2D swordfighting “prototype”.

I’ve hit a snag when it comes to animating the character though, when it comes to the character rotating or turning.
My little character guy here is made of various sprites parented and childed together so he sort of works like a puppet. I semi-achieved what I wanted in one of the animations as follows:

39137-swordguy2.png
39138-swordguy3.png

At the start of the animation I start scaling the shield to make it more “flat”. After that I deactivate the shield gameobject and activate a second shield gameobject which has a different sorting layer and sprite. The result is that it looks like he turns his shield to face forward. This was all done within an animation.

Now I am curious how I could do this with more complex animations, such as the character swinging his sword in a horizontal motion, or the character turning to face the camera. I noticed it’s possible to change which sprite is rendered during animation but I can’t change the sorting layer. As an example, if the character turned to face the camera and I made his “background” arm stretch across his chest it would be drawn behind his torso…

So… do I really have to create a whole series of second gameobjects with alternative sprites and swap them in and out during the animation process? It seems like this would be a very inefficient way of doing things that could undoubtedly be solved in a more practical manner.

Any information, advice, tips, links or tutorials would be most appreciated.

This thread might help you:

http://forum.unity3d.com/threads/dynamic-draw-order-or-2d-z-buffer.220231/

Specifically this post:
http://forum.unity3d.com/threads/dynamic-draw-order-or-2d-z-buffer.220231/#post-1475523

The idea is that if all of the sprites are in the same sorting layer and with the same ‘order in layer’ value you can use the “z” value of the sprites’ transforms to determine which draw in front of one another. As part of your animation you can change the z values of the different sprites to make the arm move in front of the chest, for example.

I have not tested this myself but it seems that in theory it should achieve the effect you are looking for.