Avindr / MxM-IssueTracking

7 stars 0 forks source link

No event available for when MxM finishes OnAnimateMove. #176

Closed freyzor closed 1 year ago

freyzor commented 1 year ago

The particular use case is when using MxM with physics update with a rigid body character. OnAnimateMove is the last thing that unity does before updating the physics state and you need to be able to apply the root motion generated. Part of the problem is that one or more different methods can be called on the IMxMRootMotion interface making hard to know when it's done updating or which methods will actually be invoked. I would propose adding a on complete or finalize method to the root motion interface that would always be the last thing called during OnAnimateMove. This would make it simpler to apply the needed rigidbody updates before the physics engine runs. The issue I was running into was that updating the character in OnFixedUpdate was working with stale data as the OnAnimateMove and subsequent physics update happen after OnFixedUpdate and waiting until after Fixed update is to late as it misses the internal physics update.

This issue was most pronounces when executing an event with contact warping where the frame delay had unpredictable effect while trying to reach the contact point. It could results in loops, snapping at contact point and corrupted timing and trajectories.

Unity Execution Order for reference https://docs.unity3d.com/Manual/ExecutionOrder.html

my workaround was to do the simplest least invasive change I could get get away with and add a SendMessage at the very end of MxMAnimator.OnAnimatorMove. That makes it easy to reapply or redo with future updates of MxM.

Avindr commented 1 year ago

A finalize function has now been added to the IMxMRootMotion interface which is called at the end of OnAnimateMove