Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question [Animation C# Jobs] How to properly modify root motion in IAnimationJob.ProcessRootMotion()

Discussion in 'Animation' started by superkerokero, Sep 30, 2022.

  1. superkerokero

    superkerokero

    Joined:
    Dec 9, 2015
    Posts:
    8
    IAnimationJob provides a method called "ProcessRootMotion", as its name suggests, it's supposed to be used to process animation' s root motion.

    ProcessRootMotion() has AnimationStream as the parameter.
    AnimationStream has properties of "rootMotionPosition" and "rootMotionRotation", but these are READ_ONLY, meaning you can't modify them.
    In addition, AnimationStream provides "velocity" and "angularVelocity", which are supposed to be avatar's velocities. These are writable, but I can't figure out how to use them to modify root motion that comes with an animation.

    Example 1.
    The character and animation is taken from mixamo.com.
    In this case, the animation is "capoeira", which has root motion that moves the character around.
    Setup the character with custom animation c# job like this and modify the velocity and angular velocity to zero. The expected result would be that the character stops moving around.
    But character's trajectory changes to a straight line, still moving.

    Original animation:


    Set velocity and angularVelocity to zero:


    Code (CSharp):
    1.         public void ProcessRootMotion(AnimationStream stream)
    2.         {
    3.             stream.velocity = Vector3.zero;
    4.             stream.angularVelocity = Vector3.zero;
    5.         }
     
  2. superkerokero

    superkerokero

    Joined:
    Dec 9, 2015
    Posts:
    8
    Original animation gif:
     

    Attached Files:

  3. superkerokero

    superkerokero

    Joined:
    Dec 9, 2015
    Posts:
    8
    Set velocity and angularVelocity to zero:
     

    Attached Files:

  4. dyno_sam

    dyno_sam

    Joined:
    Jan 14, 2020
    Posts:
    2
    I'm trying to make an Animation Rigging constraint for full-body tracking and have the same issue with trying to modify the root motion in
    Code (CSharp):
    1. ProcessRootMotion(AnimationStream stream)
    Any progress on this @superkerokero?
     
  5. superkerokero

    superkerokero

    Joined:
    Dec 9, 2015
    Posts:
    8
    @dyno_sam
    It seems that you can't modify/overwrite the root motion baked into animations inside "ProcessRootMotion()". This function only allows you to add some custom processings to the baked root motion, such as adding a vector to the already existing velocity.

    In order to modify the root motion itself, you have to use OnAnimatorMove, which is a monobehaviour message that only works with an Animator component attached to the same gameobject. The baked root motion can be accessed through Animator.deltaPosition and Animator.deltaRotation, both values are modifiable.