Animation in higher layer does erase animation in lower layer

Hello everyone,

I am using Unity 5 and I want to create a 2d game. I have idle, jump and run animations for my 2d character. I now want to add a waving animation which should partly override the other animations when triggered.

My idea was to create a sprite sheet (I am using Pyxel Edit) with my waving animation which covers only a part of my 2d characters body.

To visualize this for this post here, I created some dummy sprite sheets.

Basic Animation (e.g. Idle):

Waving Animation:

Now, in my Animator in Unity, I put the basic animations on my Base Layer, and created a second layer where I put the waving animation.

And here comes the problem: When I start the game and make my character wave, the waving animation is played, but only the waving animation body part, and not the underlying basic animation with the rest of the body. In other words: It looks like for a moment my character looses the hat and the feet.

I tried many things: I set different weights, I tried Override and Additive Blend Modes - no combination seemed to work.

Some posts and also the Unity manual suggest to create a mask for this issue, but I couldn’t find any hint how to create a mask for a 2D sprite sheet, all guides are for 3D Models. I also found AddMixingTransform, but can also be used only with a mask.

I also tried to cut my waving sprite sheet on top and border, like this here:

Waving Animation “Mask”

That also did not help.

Does anyone understand my problem and how I could solve it?

To me it sounds you are mixing Unity animation concepts.

Animator and mecanim work mostly with “standard” 3D skeleton, base layer and layers, additive mode and masking are for “masking” certain bones out from transform calculations or layering 3d animation and don’t make much sense for 2d sprite animation in many cases.

I’d go for multiple sprites and layer them using Sprite Renderer’s “Order in Layer” option. Search for unity sprite animation and you’ll find more information most likely, and check out “2D Roguelike Tutorial” maybe?

Hi eses,

thank you very much, you showed me the right direction and new ideas where to continue researching. I managed to proceed a bit! This is how:

I created a new Game Object on my Player and attached a new Animator Component to it. This new Animator contains only the waving animation, and it’s Sprite Renderer Sorting Layer I set to Foreground, Order in Layer 0 (like my other Animator component).

But I still got a little problem here. The waving animation part is shown with the rest of the body, but also the animation behind is still shown - so my character waves (waving animation) and moves his arms (running animation) at the same time, and it looks like he suddenly has 3 arms.

To make this even stranger, with the idle animation it seems to work - the wave animation overrides the idle animation as wanted.

Any ideas?

EDIT: At least the last point is now clear to me: It overrides the idle animation because the waving animation has - I don’t know how else to express it - pixels drawn there. This means for the problem with the running animation, that the moving arms are shown in those places where my waving animation has nothing drawn there (is transparent). I dont want that…I want my waving animation overrides the running arms with transparency (because the background should be shown of course).

If anyone is interested, here is how I solved my poblem. I am not sure if this is the way how it is supposed to work, but I couldn’t find anything else to work out.

I basically made new sprite sheets :rage: I took the existing ones and made sprite sheets only containing the arm, and the other ones containing the body without arm.

Then I created a new Animator (arm) component on my Player Game Object and put its Sprite Renderer Component on a Layer above the already existing (now body) Animator.

I created new Animations for both arm and body part and put them into the respective animators, I also had to create new state/transitions and so on…

I had to create also the same parameters for the new Animator, and trigger them also additionally in my code, so the animations are in sync (where I think I still got a small issue when my waving animation interrupts the running-arm-animation and when it gets back, i think the running arms animation is out of sync with the body run-animation, but it is almost not visible thanks god.)

I am SO unsure if this is the correct solution to my problem, I tried it really with only one Animator and two layers, but that simple does not work since you can’t create a mask for 2d Sprites - without the mask one layer always eliminates the complete animation of the other layer.

Anyone can confirm that my approach is somehow correct, or is there another way to achieve this more simpler?