• Unity
  • animation event on first frame not firing

hi,
we are encountering problems with events not firing if they are located on the first frame.
all the other events fire just fine.

we play animations using the SkeletonAnimation component like this:

var trackEntry = skeletonAnimation.AnimationState.SetAnimation(0, "dodge", false);

after calling SetAnimation i can even find the event on frame 0 by querying all events like this and iterating through them:

trackEntry.Animation.Timelines.Where(x => x is Spine.EventTimeline).SelectMany(x => (x as Spine.EventTimeline).Events)

Package version: spine-unity-4.1-2022-05-09-beta.unitypackage

is this a known thing?

Related Discussions
...
  • Изменено

Missing events of the first frame are not a known problem. Usually missing event problems arise when mixing out and Trackentry.EventThreshold was not setup accordingly.

From where are you calling AnimationState.SetAnimation? Are you sure that your event registration and callback code works properly? If so, could you send us a minimal Unity project that still shows this issue? You can send it as a zip package to contact@esotericsoftware, briefly mentioning this forum thread URL so that we know the context.

hi Harald, thanks for answering. EventThreshold related stuff was all i could find by searching too. while preparing the minimal project i now found the source of the problem:

we have a special case where our character needs to switch to a different version of the current animation and continue with the current animation time. i did the transition by starting the new animation and setting trackEntry.AnimationStart to where the old animation was.

now the problem is that i also set trackEntry.AnimationLast to the same time to avoid firing all events that come before that time. that's fine for this special case but i use the same code for starting all animations which will set AnimationStart and AnimationLast to 0 for all the other animations.
As i now found in the docs:

AnimationLast defaults to -1 to ensure triggers on frame 0 happen the first time this animation is applied.

i think i will solve our problem by checking if the animation to play should start at some offset bigger than 0 and only then set AnimationStart and AnimationLast to the offset value.

Glad to hear you've figured it out.

grimbart_rene написал

i think i will solve our problem by checking if the animation to play should start at some offset bigger than 0 and only then set AnimationStart and AnimationLast to the offset value.

This sounds like a reasonable approach.