KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
67 stars 8 forks source link

Zero-frame Animation events on Restarted Clip States don't fire #65

Closed bennettdc closed 4 years ago

bennettdc commented 4 years ago

Environment

Description

When replaying a clip that is already playing using e.g. Play(_clip) or Play(_clip,0,FromStart), the first frame's (Unity) Animation events do not fire.

Reproduction

Steps to reproduce the bug:

  1. Open Examples/01 Basics/05 Simple Hybrid
  2. Edit SimpleHybrid.cs: (or rename the attached SimpleHybrid.txt and replace it) 2a. Change _Animancer.Play(_clip) to _Animancer.Play(_clip, 0f, Animancer.FadeMode.FromStart) for both _TennisForehand and _GolfSwing 2b. Add a new serializefield: [SerializeField] private int _numSwings; 2c. Add a new function for demonstration: public void CountSwings() { _numSwings++; }
  3. Add events to the animations 3a. In Unity, edit the Humanoid-GolfSwing animation, adding a CountSwings() event at frame 0. 3b. In Unity, edit the Humanoid-TennisForehand animation, adding CountSwings() event at frame 1.
  4. Open DefaultHumanoid in the inspector to watch the _numSwings field.
  5. Enter Play mode.
  6. Test GolfSwing 6a. Press GolfSwing. Note that numSwings increases by 1. 6b. Press GolfSwing again quickly. Note that numSwings does not change. 6c. Press GolfSwing again after waiting for the animation to finish and freeze. Note that numSwings again, does not change.
  7. Test TennisForehand 7a. Press TennisForehand. Note that numSwings increases by 1. 7b. Press TennisForehand again, Note that numSwings increases by 1 again.
  8. Test them together: 8a. Press GolfSwing, then TennisForehand, then GolfSwing in quick succession. Note that numSwings increases by 3.

Therefore an event at frame 0 does not fire if its animation clip is restarted. All other events work fine.

Further notes

I have tried messing around to circumvent this, to no avail. Adding code to micro-switch animations right before switching back doesn't help, nor does Stopping the animation first, nor does setting the time of the animation to 0. It only fires if switching from a different state.

SimpleHybrid.txt

KybernetikGames commented 4 years ago

Unfortunately, this is a Unity bug which I have no control over (Case 1230811). As noted in my bug report, you can work around it by opening the animation in a text editor and changing the event time to a really small value like 0.0001 instead of 0. This is one of the reasons I implemented Animancer Events.