- Edited
[Unity] Switching between animations images keep state
Hi,
Note: I am the programmer using spine skeletons that I am given, so I have no knowledge of Spine itself, so please excuse my ignorance when it comes to terminology.
I am trying to switch between the animations of my character using simple SetAnimation calls however any of the parts of the character that are not affected by the next animation seem to just stay in the state they were at when I called SetAnimation.
ex) You see the problem in action in the following GIF. I play my blastoff animation and switch to my idle part way through, the character's torso doesn't re-appear, and the clouds stay. Similar effects happen for every animation, they play and look fine inside of Spine. Image removed due to the lack of support for HTTPS. | Show Anyway
Hi UncleAcid,
As far as I know, this is the intended behavior at runtime. I believe this is intended to allow one to overlay multiple animations on top of one another. I think the fix lies in the animations created in Spine. I'm pretty sure you need to ensure that on the first frame of any animation that any attachments/bones have their texture/position/rotation/scale set to what you need for that animation (or to some default value that you expect). If they are not implicitly reset by you then they will inherit whatever values any preceding animation last left them at, as you are encountering. This may seem like a nuisance, but the system actually allows for some very powerful animation layering if you explore it later on (animate legs, arms, head, you name it, using different, non-interfering animations all at the same time). So I guess I would recommend instructing your animators/Spine skeleton creators to insert keyframes at the beginning of animations to override anything that may come before and set the skeleton to default values for that animation.
Hopefully someone else can verify my answer.
Regards,
Rob
P.s. I think there is a skeleton.setToSetupPose() function, or something similar which you could call before you set animation. That would probably provide the functionality you want by resetting to the default setup pose. This is what is happening when you play the different animations in Spine itself.
P.p.s. Actually just found it in the documentation here.
Thanks Rob, you nailed it!
Wow, very detailed and informative answer. Thanks Rob, that makes perfect sense.
Calling setToSetupPose() before setting the animation works great. I remember trying that but calling it after SetAnimation(), not sure why I never tried before, oh well.
Only issue now, and I believe it's related; is that with the same blastoff animation at the end of it the torso of the character is hidden and when I have that animation on loop the body doesn't come back until I call setToSetupPose and SetAnimation again. Is that intended as well ? are the only options for that to either key all the animations in Spine or have a callback for when the animation ends and manually loop it so I can reset the skeleton ?
Thanks.
Pretty much, yes.
http://esotericsoftware.com/spine-using ... on-changes
OK. Thanks for all the help Rob and Nate.
Hello thank you for this useful information,i used to have the same problem but when resetting the first frame it worked,but now i am facing a new problem the animation is no longer looped after resetting the first frame to default pause,is there any way we can have the animation looped ,when resetting the first frame?
any help would be appreciated,thanks.
Nothing about this stops it from looping.
Can you share your code?
Are you using Unity too?
Thanks for your response what i mean is that i have several animations within the same file for example(sad,cry,happy and so on) each from these animations has a unique first frame for example the sad animation's first frame is frowning,and the happy is smiling,now I had to reset the first frame to default pause as some items where disappearing,but now each animation starts with the default pose which causes each animation at the end to jump at the default frame poses as a result animations are not looped any more do you have any solution?
That is quite a long sentence.
Changes an animation make to a skeleton are persistent. Keep this in mind if you have animations that change what attachments are visible. If you play animations that hide an attachment, when you play other animations it will still be hidden. You know what attachments you hide, so maybe you need to shown them again when you change animations.
It sounds like you are using setToSetupPose
when the animation changes. Maybe try setSlotsToSetupPose
, so your bones aren't affected.
hahaa sorry about that,thanks soo much for your reply will try it and get back to you
Thanks a lot the setSlotsToSetupPose solved the problem,however now i am facing another problem .
I have to reset each animation to default pause as when flipping between animations at run time for example scale( in jumps animation) affects the bones in sad animation.
But how can i reset and freeze the transformations while each animation has a unique first frame which differs from the default pause?
In other words when switching between two animations in real time how to stop bones from inherting the pevious values in the previous played animations???
for example i have scale values on bones in jumping animation,in unity when switching to other animation while its playing the scale affects the next animation,can you please help??????
Key the bones at the start of your animations. An animation only changes what is keyed.
I don't see a method called setToSetupPose on any of the objects in my Unity project.
I have problems with the way we switch animations, so if an animation doesn't set keyframes at the beginning with get bones staying set with whatever was last in the previous animation. I can't ask my animator to go back and put a keyframe on every animation and re-export everything. This seems like the perfect fix, but it doesn't seem to be available. Is this just an oversight or am I looking in the wrong place?
Any help would be appreciated.
What you mentioned is not a perfect fix. It's a hassle. Auto-reset is cleaner for your workflow.
Here's where SetToSetupPose is:
var mySkeletonAnimation = GetComponent<SkeletonAnimation>();
mySkeletonAnimation.skeleton.SetToSetupPose();
See a sample auto-reset code here: A little Unity help requested
Here's even more info: [Unity+tk2D] Problem setting two animations in same frame?