• RuntimesUnity
  • Reset mesh deform animations

I am using some mesh animations do deform meshes. For example simple sword trails for attack. It works nicely. It is also possible that player can be interrupted by HURT animation, if enemy will hit player first. Unfortunately it results also, that mesh animations (sword trails for example) will not complete mesh deform animation and will be kept forever. This results player in IDLE with deformed mesh (sword). I would like to call some Spine method on HURT, just to reset all mesh attachments deforms, caused by any mesh deform animations. Is it possible. Something like skeletonAnimation.state.ResetToSetupMeshDeforms().

Related Discussions
...

To reset all mesh attachments deforms caused by any mesh deform animations, you can use the SetToSetupPose method on the skeleton. This method will reset the skeleton, including all mesh deformations, to the setup pose. Here is how you can do it:

skeletonAnimation.AnimationState.ClearTracks();
skeletonAnimation.Skeleton.SetToSetupPose();

This code will clear all current animations and reset the skeleton to its setup pose, effectively removing any deformations from mesh animations.

If you need to reset only specific mesh deformations without affecting other parts of the skeleton, you might need to manually reset the vertices of the mesh attachments. However, the above method is the most straightforward way to ensure all deformations are cleared.

Using clearTrack or clearTracks will leave the animation pose. You can use SetToSetupPose as Spinebot mentioned, or you can use empty animations to mix an animation back to the setup pose.

  • Maltakreuz ответили на это сообщение.

    Nate

    Hi, I just have tried it. Yes, it works. As you could see in my screenshot I have pretty many attachments, so after call SetToSetupPose() I also need to bring all armor elements back. It currently has also downside that sword pretty fast goes to setup pose position instead where it was, resulting some "jump":

    So it works for me already, and this jump and reattachment is not that bad. But if there is some better option to reset all mesh deforms, without calling SetToSetupPose(), that would be great.

    So could you explain a little bit more about empty animation. Do you mean just calling
    skeletonAnimation.state.SetEmptyAnimation(0, 0); will reset mesh deforms? As far as I understand, there is no keyframes for mesh deforms in empty animation, so how this supposed to work?

    I did not manage to reset mesh deforms just by calling
    skeletonAnimation.state.SetEmptyAnimation(0, 0);

    but SetToSetupPose() works fine for me too. Sword position jump is auto-mixed for default 0.2 sec, so it is smooth enough.

    • Misaki ответили на это сообщение.

      Maltakreuz As far as I have tested, resetting the mesh deformation by setting an empty animation works correctly.
      Did you make sure the sword animation was played on track 0? If you looked at the Spine Runtime Guide page that Nate introduced, you've probably already read this, but the first argument to setEmptyAnimation() is the track index. So for example, if the sword animation played on track 1, you'd have to call skeletonAnimation.state.SetEmptyAnimation(1, 0); to reset the pose given by the sword animation.

      Make sure you do not call clearTrack, clearTracks, and do not set trackEnd.

      Thank you, it works indeed. I just should not call ClearTracks() anymore to make empty-anim to make such effect.