- 編集済み
Chaining animation resets elements to their set-up pose.
Hello,
I'm trying to chain 2 animations in the same track index using Set and Add. The first animation (Set) is kind of an apparition animation and the second animation (Add) is an idle animation (loop : true). When the second animation is played all previous animated elements that are not animated in the second animation are set to the set-up pose. I thought that it won't happened and instead elements not involved in the second animation will remains as they are.
In order to be sure I used an empty animation (no key) as the second animation and all elements are set back to their set-up pose.
- Is it normal ?
- How can I chain 2 animations and not having all elements not used in the new animations reset ? I don't really want to put a key for all elements because it's not convenient.
Thanks
If you play one animation and then another on the same track, you should not expect the first to continue being applied. The first is mixed out over the TrackEntry mixDuration
, then it is no longer applied and only the second animation is applied.
What you want is to apply two animations at the same time, on different tracks. Do setAnimation
on track 0 for the first animation and setAnimation
on track 1 for the second animation. You can mix the track 1 animation in/out by using AnimationState setEmptyAnimation
.
See here:
Applying Animations - Spine Runtimes Guide: Tracks
Hello,
I don't want to play 2 animations at the same time and I don't want the first animation to continue to be applied. I want to play animation A on track index 1 and then animation B on track index 1. I want all bones moved by animation A and not moved by animation B to stay as they are at the end of animation A.
For example, totally imaginary example, during animation A a character sit-down and on animation B the character waves its hands. I want the characters to be still sat down when B is playing.
It's not really about having A still be played but more having the skeleton as is when the animation is ended that way when the next animation is played it stays as is and only bones moved by animation B are updated.
You can use TrackEntry holdPrevious to hold the previous animation:
skeletonAnimation.AnimationState.SetAnimation(0, "sit-down", false);
var waveEntry = skeletonAnimation.AnimationState.AddAnimation(0, "wave", false, 0);
waveEntry.HoldPrevious = true;
holdPrevious
will keep A being applied during the mix to B, but not after the mix is complete.
AnimationState used to work like you want
instead of mixing properties that are not keyed in the next animation back to the setup pose, those properties would just be left at whatever values the previous animation keyed. This leads to needing to key all properties at the start of every animation as a way of starting from known state. This isn't great, as it means a lot more timelines are needed.
There is still a way to do what you want. If you use mixing, even with a mixDuration
of 0, then properties keyed in the previous animation but not keyed in the subsequent animation will be reset to the setup pose. However, you can use TrackEntry clearTrack
before setting the second animation. This removes the first animation without resetting anything to the setup pose. When further animations are played, they will only affect the properties they have keyed, so any skeleton state from the removed animation will remain.
I still suggest to use separate tracks rather then relying on the skeleton state set by previous animations. Eg, if your character is sitting, standing, walking, etc set those on a track. Actions like waving, aiming, etc that are to be played on top would be set on a higher track.
Hi Nate, thank you for your reply.
We've been using Spine since the first version (I work with bali33 in the same team) and are still very happy
So one of the spine file is a character with a lot of animations. We have of course set many tracks for a very accurate control (head orientation, body animation, blink, emotion, eye orientation...)
However sometime we need to make more complex animations and breaking them into several animations to be played in several tracks is not something I plan to do. So hard to maintain, and I don't want to add one animation per track for that (since there are already so many animations in the spine file).
For exemple, I have my character standing in some kind of idle state, where I can control what it is doing (so controlling each different tracks is very useful) but then I want to launch an animation where the characters jumps and makes a 360° spin on itself.
and then back to idle.
(link if the animation doesn't show: https://imgur.com/T8kHvBx
So as you can see here, back to idle makes a jump cut I don't really want.
This is probably because the spin animation is on one track only, while the idle animation plays several animations on different tracks.
What do you suggest so the transition uses the mix animation ?
thanks
If you want the old behavior (state from previous animations is not reset to the setup pose) and you want mixing, I'm afraid you'd need to edit AnimationState. I think the change is simple, find this line:
from.totalAlpha += alpha;
And replace with:
timelineBlend = MixBlend.replace;
from.totalAlpha += alpha;
Or you could allow mixing to empty animations:
if (to.animation.timelines.notEmpty()) timelineBlend = MixBlend.replace;
from.totalAlpha += alpha;
This last one will let you set an empty animation to mix out an animation to the setup pose, but only the properties keyed in that animation will mix to the setup pose. State left from previous animations will stay.
You'll need to use Skeleton setToSetupPose
or Skeleton setSlotsToSetupPose
or Skeleton setBonesToSetupPose
to reset the skeleton state, or otherwise manage the state using animations or code that gets slots and/or bones and resets them. There is also Slot setToSetupPose
and Bone setToSetupPose
.
thank you
I think It's probably not a good idea to start editing runtime code so we'll probably will look at something else (maybe the cleartrack solution).
The thing is that we have to create our own framework to handle all those animations and tracks for now, where I can define, when my Spine animations are done, which animation goes in which track. In an ideal world this could be done in the spine editor, but that is probably off topic, and I will create one for this in the editor section of this forum.