• Runtimes
  • [Unity] Event not fired during animation mix

Hi, I'm getting a problem where defined events are not firing when placed within the last 5 frames of an animation.

This only happens if I'm mixing to another animation via 'AddAnimation'.
If I use 'SetAnimation' after the previous animation completes, then it fires correctly in the final frames, but then I lose the nice blend.

So it seems any events defined within mixed frames are ignored, is this correct? If so, is that a bug that could be fixed?

Thanks!

Related Discussions
...

How long was the mix? (just for more info to look into it)

I'm thinking the code that handles it is somewhere here: https://github.com/EsotericSoftware/spi ... te.cs#L114

Line 116 is particularly suspicious:

previous.animation.Apply(skeleton, previousTime, previousTime, previous.loop, null);

I think I kinda see where the problem is but we need to trace back how previous is updated.

[EDIT]

Try to find AnimationState.cs in your Unity project and replace it with this attached file.
The first question still stands though, how long was the mix?

Thanks Pharan, I gave that a try but it didn't seem to work I'm afraid. I didn't set the mix to any specific value, so I'm assuming it's using some default?
I'm just adding the second animation with the regular stub - AddAnimation(int trackIndex, Animation animation, bool loop, float delay)
This seems to mix with some default value.

SkeletonDataAsset has that default mix value. Try setting it to zero.

I think I just made a careless mistake.
Try this one?

[FILE DELETED]

Doh, nope still no luck sorry Pharan. Mitch, I dropped the mix value to 0 and sure enough, the event will fire with no mix. It was set at 0.2.
I'll keep trying to figure it out. I really need that event fired in the last couple frames but along with the mixing.

Thanks for the help so far.

I'll take a proper look at this when I get in. Thanks for spotting it - its definitely a c# issue and not isolated to unity.

Hey. I got this. Get your own turf. XD
Actually, I found the problem. I didn't have a test setup before so I couldn't tell what was really going on.
I solved the first problem of the events not fitting into the time range. I just needed to bring it into the AnimationState class and fire it. I thought it would need a few extra lines but it turns out, I just needed to replace null with the existing events list. (turns out Nate was passing null, meaning he might have intended for events not to fire during a mix?)

And done. FOR SURE this time. I've seen it work with my own eyes.
Third time's the charm. The total number of lines changed/added since the first post were like... 3? 4?

The other thing I found is that if you're mixing, Complete doesn't fire on the first animation either. I'm actually not sure which behavior makes more sense; this or a firing one.

Made a PR though. Didn't try to fix Complete not firing.

Yay it's now working Pharan. Thanks so much for your help!