• Unity
  • Animation playing incorrectly when using override in mecanim

Related Discussions
...

Hi,

I am having trouble using override in mecanim when playing animations from different layers. I have ensured that all the relevant bones are keyed, but the animation does not work properly when it is played from a different layer. If I play it from the same layer there are no issues, but this would be very cumbersome. I don't know if I am doing something wrong.

Grateful for any help.

Thanks

In which way does the animation look incorrect? Could you please describe in more detail what is wrong (what you got vs. what you expect) or share a video or screenshot?

Could you please also show some screenshots of your Inspector settings of your SkeletonMecanim component, especially the last section Translator (or Mecanim Translator in recent versions) would be intersting to see.
Please also share a screenshot of your Mecanim layers in the Animator panel.

Thanks for the reply.

I created a simplified version of the sprite and the animation, and the problem persists.

If the animation is played from the attack layer using override (weight is 1), the weapon appears not to be in the characters hand throughout the animation. However, it works fine in Spine. It also plays properly if I transition the attack animation from the idle animation in the same layer.

This is how the attack animation looks like at the end with the layer override:

This is how it is meant to look. This is how it looks if the animation is played from the base layer i.e. transition from idle to attack:

This is the simplified base layer with only the idle animation:

The Attack layer:

Below is the mecanim component from the Inspector:

Let me know if I need to provide any further information.

I think the second Layer Mix Modes entry is the problem here. Try setting Element 1 to Always Mix.

You can also download the latest spine-unity unitypackage, it comes with a new parameter Custom MixMode which you can disable to use the recommended settings:
spine-unity Runtime Documentation: SkeletonMecanim Component
We have added this since these parameters are pretty counter-intuitive.

Thanks for the reply.

I changed the mix mode and this did not work. I therefore updated the unity runtime. I tried using Always Mix and then I disabled Custom MixMode in Mecanim Translator. None of these settings resolved the problem.

Could there be something wrong with the way the animation is setup in Spine?


Created a new simply animation and I have encountered the same problem. It plays fine, if it is within the same layer, but override is not working properly. Now, some of the images disappear.


I have slowed it down, and what is happening is that the Idle animation continues to play and the Attack animation does not properly override the relevant bones. This seems to be why the animation does not play correctly.

Could you then please send us a minimal Unity project that still shows the problem, as a zip package to contact@esotericsoftware.com, then we can have a look at what's going wrong.

The project has been sent. I had to split the project into 3 zip files to be able to send it. The project was larger than expected given that it only has the character animation and a simple script to play the animations.


files appear to be rejected by the esoteric email

7 天 后

Please note that you can delete everything except for the Assets and Project Settings directories. We don't need the Library etc directories.

You could also upload it somewhere (wetransfer, google drive, dropbox) and send us the link via email.


Thanks for sending the reproduction package. Unfortunately we could not reproduce the issue from the reproduction package. It worked as intended (showing behaviour as in your second screenshot) when we opened the project in Unity and hit the left or right mouse buttons, same as when hitting the trigger parameters manually to start the override animations.

We used Unity 2019.3.15f1 instead of 2019.3.0f6 (as we've already got 16 different Unity versions installed in parallel), but I rather think that this has something to do with re-importing the assets. Could you have a try if the reproduction package works on your end when you re-import all assets? If it still shows the error, you could have a try installing Unity 2019.3.15f1 and see if it fixes it on your end as well.

A side note, which did not change anything however:
Your Mecanim Translator setup now shows Always Mix at both the Base Layer and the Attack layer. I have recommended you to change only the Attack layer to Always Mix and leave the Base Layer at Mix Next. This is the same as disabling Custom Mix Mode and thus using the recommended mix mode instead.

Hi

Many thanks for the reply.

The reason why you have been unable to reproduce the error is because I left various animation assets in the unity folder, which I had been trying out. The one that was playing was not the one that had issues. I apologise for this.

I have been able to reproduce the error by changing the Attack animation that is activated by the right mouse button.

At the moment the animation controller is referencing Attack3, which is in Assets/C4/Character_Controller.controller . It needs to reference Attack2, which is also found in Assets/C4/Character_Controller.controller. What you should see is that the weapon is not visible throughout the animation, when it ought to be visible.

I have exported the animation again from Spine and imported it into Unity and the issue still occurs. It is visible in Spine, but not in Unity.

Kdrago :

The reason why you have been unable to reproduce the error is because I left various animation assets in the unity folder, which I had been trying out. The one that was playing was not the one that had issues. I apologise for this.

It is not a good idea to experiment in the reproduction project after it already reproduced the problem and package it after experimenting, but I guess you learned that now.

Please also do not leave various unnecessary assets in the minimal reproduction package. This is why it is called minimal, it should include nothing but the required reproduction assets.

Kdrago :

I have exported the animation again from Spine and imported it into Unity and the issue still occurs. It is visible in Spine, but not in Unity.

Actually this is not correct. When using the Preview window in Spine and layering Idle and Attack 2, it shows the same result as in Unity, the attachment being hidden.

Your problem here is simply that you hide the attachment at the start of the Idle animation on layer 0, and then on layer 1 you play Attack 2 which does not change (key) the visibility of the attachment. When you only view the Attack 2 animation in the main view, it uses the visibility of the Setup state, which is visible. So the solution is as with Attack 3 which keys the visibility to visible, so it is shown as desired.

Thanks for the reply, I am grateful for your patience and help.

Actually this is not correct. When using the Preview window in Spine and layering Idle and Attack 2, it shows the same result as in Unity, the attachment being hidden.

Your problem here is simply that you hide the attachment at the start of the Idle animation on layer 0, and then on layer 1 you play Attack 2 which does not change (key) the visibility of the attachment. When you only view the Attack 2 animation in the main view, it uses the visibility of the Setup state, which is visible. So the solution is as with Attack 3 which keys the visibility to visible, so it is shown as desired.

I have checked the Spine 2d file, and this is not the position. It plays fine in preview mode. The Attack2 animation has the weapon 'keyed' as visible on the first frame and Attack3 has it visible (Key) as from the 3rd frame because the character arm moves up to grab it. In preview mode all animations play correctly. I have now keyed the weapon as visible on all frames in the Attack2 animation and the same thing happens when it is exported to Unity. Shall I send the Spine 2d file?

5 天 后
Kdrago :

I have checked the Spine 2d file, and this is not the position. It plays fine in preview mode.

When using the asset from your reproduction project, it showed the same problem in the Spine Preview window when playing Idle on track 0 and playing Attack 2 on track 1. Do you not see this result in the Preview window (not the main window)?

Kdrago :

I have now keyed the weapon as visible on all frames in the Attack2 animation and the same thing happens when it is exported to Unity. Shall I send the Spine 2d file?

Yes, please.


Thanks for sending the reproduction asset.

The problem was that you enabled Animation clean up when exporting the json file, this has to be disabled when using animations on higher tracks (described here). When re-exporting with Animation clean up disabled, it behaves as expected.