- Изменено
Unity: AddAnimation ignores TimeOffset
(Not sure if this really is a Bug or I am just using the API in a wrong way)
I want to start an animation
- With a MixDuration (but without a previous TrackElement on the same track)
- With a time offset (start the animation at frame X > 0)
What I Did:
- Installed spine-unity-3.8-2019-09-05
- Opened the [2 Controlling Animation] Example Scene
- Modified the DoDemoRoutine() in SpineBeginnerTwo.cs to the following
[Range(0.0f, 1.0f)]
public float offsetRelative = 0.0f;
IEnumerator DoDemoRoutine ()
{
while (true) {
// just for better ovservability
Time.timeScale = 0.2f;
// As advised in http://esotericsoftware.com/spine-applying-animations#Empty-animations
spineAnimationState.SetEmptyAnimation(0, 0);
// We want to start with an offset (as advised in http://esotericsoftware.com/forum/Is-Spine-Animation-has-cycle-offset-for-looping-animation-6621 )
var track = spineAnimationState.AddAnimation(0, walkAnimationName, true, 0.0f);
track.TrackTime = offsetRelative * track.AnimationEnd;
track.MixDuration = 0.01f; //< just for better observability
yield return new WaitForSeconds(0.2f);
// Reset to idle
var track2 = spineAnimationState.AddAnimation(0, idleAnimationName, true, 0);
track2.MixDuration = 0.01f; //< just for better observability
yield return new WaitForSeconds(0.2f);
}
}
What I expected:
- The Run Animation starting on different frames depending on offsetRelative
What I observe:
- The Run Animation does not consider the offset, I put into TrackTime
- When I change the AddAnimation() calls to SetAnimation() the offset works as expected, but SetAnimation() seems to not support the MixDuration from the EmptyAnimation
Is this a bug or am I doing something wrong?
I'd recommend not directly modifying the TrackTime
but instead just supply the offset as a parameter to the call to AnimationState.AddAnimation()
(it's the last parameter). An alternative, since you do this in a co-routine way using yields and WaitForSeconds
, would be to just put the calls to yield
in front of the calls to AddAnimation
with the relative offset you want.
Sorry if i didn't specify my intends unambiguously:
I don't intent to delay when the animation will be switched.
I just want to say that the animation should start in its middle (as if it had started some seconds ago). (a "cycle offset" as in the forum-thread, i linked to)
(Both suggestions (WaitForSeconds before AddAnimation, passing a positive delay to AddAnimation) lead to a delay of when the animation will be switched (in this case leaving me with the empty animation playing for that time))
(I just used the Sample-Scene-Coroutine so that you can easily reproduce it, my real problem is a bit more complex)
This seems like an AnimationState bug after all. I've opened an issue here: https://github.com/EsotericSoftware/spine-runtimes/issues/1504
This is now fixed in all runtimes on both the 3.8 and 3.9-beta branch. Thanks for reporting!
Cool, thanks!