Fix for Animator Apply Root Motion (position and rotation)

Ever wondered why your Animator breaks and stops updating position and rotation when there is also an UdonBehavior on the same game object?

Basically, udon is set up in such a way that instead of applying the position and rotation directly to the game object (ApplyRootMotion), it feeds the values into Udon itself in the Animator’s targetPosition and targetRotation variables, so udon can get the result of the animation and decide what to do, usually Transform SetPositionAndRotation.

Technically, with the same idea, you can use the Animator’s position and rotation tracks to provide per-frame data for your udon script to do anything with: you don’t have to simply set localPosition/localRotation on the transform.

Anyway, TL;DR: Please follow one of these links depending on which type of udon you are using.

Please see here for an updated fix for Udon Graph It’s recommended to use the linked program and copy and paste it into an existing udon program!

See Mimi’s reply for a solution in UdonSharp (U#)

The following only worked on the old 2018.12 SDK which supports subgraphs…
Well, if you actually just want to apply the position and rotation from your animation without processing it through udon, take the attached ApplyAnimatorRootMotion subgraph and throw it into a Sub Graph node.

1 Like

Would it be able to use this but instead off animator it uses instance as a ref for rotation.
for instance i would like to build a vr car.
using Rotation on stearing wheel to steer the left and right wheels on the car.

if you are doing U#, this will look like this to fix the issue. Get the animator in some way, then…

    private void OnAnimatorMove() 
    if (animator != null)
        transform.SetPositionAndRotation(animator.targetPosition, animator.targetRotation);

Please see here for an updated fix!