Don't bind a method that calls SetAnimation
to the AnimationState.End
event. It'll always freeze.
Bind it to Complete instead. AnimationState.Complete
fires whenever an animation finishes playing completely.
Explanation:
1) End
fires when an animation is stopped, whether by some interruption (when the animation is changed by SetAnimation
or stopped by ClearTrack
before it finishes), or when an animation finishes playing completely (when an animation finishes, AnimationState calls ClearTrack which causes End
to fire). In fact, it always fires whenever you have an animation playing and then SetAnimation
or ClearTrack
are called.
In other words, SetAnimation
calls End
, and if End
has method subscribed to it that calls SetAnimation
, it'll recurse forever: End calling SetAnimation calling End calling SetAnimation calling End... etc, etc...
2) Complete
only fires when an animation finishes playing completely from start to end. (I can see how this can be confused with "End".)
This is probably the event you want though. I'm assuming what you want is for it to detect when the animation is done and then decide what animation to play next.
For even more detailed info, you should check the code in AnimationState.cs