We have a problem with mixing between animations. We have frequent animation changes and it seems it breaks animation mixing in a way. If I try to set an animation while the previous Mix haven't finished, even if I set the their MixDuration to 0, they will still blend with the new animation for 1 frame. Since we hide some bones for some animations, multiple mixes together don't show the bones we want to be visible. Is there a way to set an animation while completely skipping all the mixes present before?
Mixing problem
To address the issue of unwanted mixing when setting a new animation before the previous mix has finished, you can use the SetAnimation
method with a mix duration of 0 to immediately switch to the new animation without blending. However, if you are experiencing a blend for one frame, it might be due to the way the animation state is being managed. You can try clearing the tracks before setting the new animation to ensure no previous mixes affect the new animation. This can be done using ClearTracks()
or ClearTrack(trackIndex)
to remove any ongoing mixes. Additionally, ensure that the bones you want visible are keyed correctly in the new animation to avoid them being hidden due to previous animation states.
KPerev Since we hide some bones for some animations, multiple mixes together don't show the bones we want to be visible.
I assume by "hiding bones" you mean you're hiding attachments? If so, and you see attachments visible at undesired times, likely you need to adjust the TrackEntry.AlphaAttachmentThreshold
.
If I try to set an animation while the previous Mix haven't finished, even if I set the their MixDuration to 0, they will still blend with the new animation for 1 frame.
Yes, see the documentation here:
http://esotericsoftware.com/spine-api-reference#TrackEntry-mixDuration
You could manually call SkeletonAnimation.Update(0)
to progress for "one frame" with delta-time 0.0 if this is undesired.
Harald I assume by "hiding bones" you mean you're hiding attachments?
From what I can tell, we have several "skeletons" in the same SkeletonData one for each direction, and when we change direction, the previous skeleton is hidden, and the next one is shown.
Harald You could manually call SkeletonAnimation.Update(0)
I've already seen this method on here while searching for a solution, but it doesn't seem to work. If my interpretation of the source source is correct, if an animation is 0 seconds into the mix it doesn't remove that animation to prevent removing the current animation (UpdateMixingFrom
method called by Update).
Spinebot Additionally, ensure that the bones you want visible are keyed correctly in the new animation to avoid them being hidden due to previous animation states.
I feel like this might be the case here, but now it depends on the animation team, I don't have the project to check it myself. I will inquire them about everything asap
KPerev From what I can tell, we have several "skeletons" in the same SkeletonData one for each direction, and when we change direction, the previous skeleton is hidden, and the next one is shown.
I'm not sure what you mean by "skeletons", as there can't be multiple actual skeletons in a single SkeletonData. If a project contains multiple skeletons, during export each skeleton would be exported as a separate skeleton.skel.bytes
or skeleton.json
file.
Unfortunately it's a bit hard to help based on such vague information. How are you switching between directional "skeletons"? Do you change animations, or skins, or set different GameObjects visible?
KPerev I feel like this might be the case here, but now it depends on the animation team, I don't have the project to check it myself. I will inquire them about everything asap
You can use the Skeleton Debug
window available via SkeletonAnimation - Advanced
and hit the Debug
button to open the debug window (see the documentation here). There you can inspect what actually happens when switching directions, which attachments are enabled and disabled, and so on.
Note that you can always use the Spine Editor and choose Spine
- Import Data ..
, then save your project and use Spine - Texture Unpacker ..
to unpack the texture atlas to an images
subdirectory. Just be sure to update the path in Images
Path
to ./images
as well.
If SkeletonAnimation.Update(0)
did not work out for you, when did you call this method? Also, did you try AnimationState.ClearTrack(trackIndex)
as Spinebot suggested? If you don't want any previous animation to have any effect on the respective track, this might be the easiest solution.
Harald How are you switching between directional "skeletons"? Do you change animations, or skins, or set different GameObjects visible?
As the animations are changed, bones of one "skeleton" are hidden and bones from another are shown. I wish I could show more, but it's not something I can post publicly. I feel like it isn't a proper way to use Spine, but at this stage we would prefer avoiding remaking most animations. If there's a way to work on this problem privately, do tell.
Harald If SkeletonAnimation.Update(0) did not work out for you, when did you call this method?
I tried using it after i set the new animation. I also tried setting mix duration for all other mixes to 0 before calling update.
Harald Also, did you try AnimationState.ClearTrack(trackIndex) as Spinebot suggested?
I also tried this, but again, it was noticeably mixing from character's default pose. I will try it again today, since there were some changes.
KPerev I feel like this might be the case here
After contacting our animators, yes, it was the case. It seems when mixing from animation A to animation B, even if B has 100% of influence on that frame, A took over some bones that were not defined in B, as they were supposed to be influenced by other bones in the animation B. After setting keys for all the bones we need, it still isn't working for some, but most of the bones that weren't appearing in the first frame, are now present. Is there a way to ignore any value given by the animation we are mixing from? I would prefer to fix it via code, if possible.
KPerev As the animations are changed, bones of one "skeleton" are hidden and bones from another are shown.
Ok, I stand corrected, those are attachments. Unfortunately I don't really know the right terminology here. We hide and show different attachments between animations, and only some bones. There are different sets of attachments between directions, and some don't appear when blending animations. Currently we are trying to see if we just have to add some more keyframes for these, hopefully it will fix our problem.
I assumed so, thanks for the clarification.
KPerev We hide and show different attachments between animations, and only some bones.
You can't hide bones directly. Bones would just be disabled if they are skin bones, which will be disabled automatically unless the respective skins are active. I doubt that you're using skin bones however.
Then your code is likely doing things at the wrong time, being too late after animations have already been applied this frame. See the documentation section on Script Execution Order here:
https://esotericsoftware.com/spine-unity-main-components#Script-Execution-Order
KPerev Unfortunately I don't really know the right terminology here.
Using the wrong terminology is not as much of a problem as not understanding how your skeleton project is set up. We would highly recommend getting familiar with the basics of Spine before attempting a more complex project. Otherwise it will be very frustrating down the road when trying to run before you can safely walk. You should at least know what Attachments, Slots, Skins, and Bones are for:
http://de.esotericsoftware.com/spine-user-guide
http://de.esotericsoftware.com/spine-bones
http://de.esotericsoftware.com/spine-slots
http://de.esotericsoftware.com/spine-attachments
http://de.esotericsoftware.com/spine-skins
If you don't know how the project was set up for directional changes, please ask the respecive artist or animator who set up the skeleton, or even better let them post the respective information here on the forum.
If you have worked out the basics of Spine and you're still having troubles, you can send us a minimal Unity project which demonstrates your problem when hitting the Play button as a zip file to contact@esotericsoftware.com, briefly mentioning this forum thread so that we know the context. Then we can have a look at what's going wrong.