Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Miyed · Sep 24, 2020 at 09:29 AM · animatoranimator controllertimelineroot motion

Timeline, Whats happening Under the Hood: with multiple AnimationTracks for same gameobject

Setup:
I have a Timeline with two tracks.

  1. Unity's AnimationTrack: Walk forward with root motion

  2. Unity's AnimationTrack: Stand in spot grumpily.

  3. A custom track that should add an additional rotation to the root motion of the animator.

A simplified Setup only using the first two tracks could also be used to answer my problem. alt text


Problem: The second animation track overrides first track.
I would like it to walk forward, stop walking, wait then play idle angry. Unfortunately, having the second animation track completely overrides the first animation track. the character doesn't walk and just stands still until the angry animation clip begins.

Why? What hidden under the hood function makes it override? Can i optionally remove this function somehow?


Problem 2: Custom clip doesnt work in Editor when there is a AnimationPlayableAsset track .
My custom clip works as desired (rotates the animator.rootRotation and transform.rotation) when it is the only track on the timeline. But when i add the AnimationPlayableAsset track to the timeline, the proper rotation values get overwritten with the root rotation from the animation track.


Limitations:

  1. I am aware that Timeline Animation Tracks only have "override" and an "additive animation" is a much desired feature but doesn't exist yet... seant_unity's answer So I'm trying to be creative.

  2. Please don't tell me: "put the clips on the same track" as that won't work for my project where i use a custom clip that is not an animation type.

  3. Please don't tell me to reorder the tracks, if i put idle on top of walk, then it plays the walk but not the idle. I need both.


Things I have tried for my custom clip to work around this:
My custom clip basically does an "additive Rotation" to rootmotion to create an effect similar to a 3rd person controller that walks straight and rotates over y:

  • transform.rotation = Quaternion.Euler(rotIncrement)*transform.rotation;

  • animator.rootRotation = transform.rotation;


  1. Hardcoded setting transform.rotation = desiredRotation; but if the first track exists, the AnimationPlayableAsset seems to overwrite the value somewhere.

  2. Creating a Monobehaviour script to update rotation in LateUpdate or in OnAnimatorIK, Works in runtime =) doesnt work in editor cause animator doesnt update. I NEED it to work in EditorMode.

  3. Using CustomMixerBahaviour.ProcessFrame to set the desired rotation of "next frame", and CustomBehaviour.PrepareFrame to set the current animator.rootRotation = nextFrameRotation.

None of the 3 alternatives work in editor when the AnimationPlayableAsset track exists above.

THANK YOU!

timeline.png (18.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by seant_unity · Sep 24, 2020 at 12:47 PM

Without additive blending, this is quite a challenging problem. Normally root motion is applied as a rotation/translation pair, it's difficult to separate them.

One solution is to use the OnAnimatoveMove callback to modify the root motion, and using timeline to set that data. Here is a quick example that modifies the rotation and still works in timeline preview.

 // These classes should be in separate files
 
 [ExecuteInEditMode]
 public class AnimatorMove : MonoBehaviour
 {
     public Vector3 addRotation { get; set; }
     public bool active { get; set; }
 
     void OnAnimatorMove()
     {
         Animator animator = GetComponent<Animator>();
         if (animator)
         {
             animator.ApplyBuiltinRootMotion();
             if (active)
                 transform.localRotation *= Quaternion.Euler(addRotation);
         }
         addRotation = Vector3.zero;
         active = false;
     }
 }
 
 
 public class AnimatorMoveClip : PlayableAsset
 {
     [Serializable]
     public class MoveBehaviour : PlayableBehaviour
     {
         public Vector3 Rotation;
         public override void ProcessFrame(Playable playable, FrameData info, object playerData)
         {
             var animator = playerData as AnimatorMove;
             if (animator == null)
                 return;
 
             animator.active = true;
             animator.addRotation = Rotation;
         }
     }
 
     // makes the Rotation editable
     public MoveBehaviour template = new MoveBehaviour();
     public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
     {
         return ScriptPlayable<MoveBehaviour>.Create(graph, template);
     }
 }
 
 [TrackClipType(typeof(AnimatorMoveClip))]
 [TrackBindingType(typeof(AnimatorMove))]
 public class AnimatorMoveTrack: TrackAsset
 {
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Miyed · Sep 25, 2020 at 10:28 AM 0
Share

Thank you very much for your fast response!! The code you gave is similar to what i was already doing, but i was missing the animator.ApplyBuiltinRoot$$anonymous$$otion();

Additionally, i need therotation change to persist when the clip is finished. So Im having to adapt it quite a bit, practically creating my own root motion accumulated rotation. But you gave me a good starting ground to work off of.

Thank you very much! I'll comment back when I get it working the way i want it!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

179 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create animations that can be edited with scripts in runtime? 1 Answer

Is there a way to get exact root motion to be applied by animation? 0 Answers

Root motion accuracy issue 0 Answers

Animator animates feet in an animation without foot animation 1 Answer

What are the best practices for reusing an animation controller? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges