Performance: Root motion
Root motion affects animation playback and character movement performance, impacting frame rendering and input responsiveness.
Jump into concepts and practice - no test required
Animator.applyRootMotion = true; // Apply root motion only when character is visible and active if (characterIsVisible) { Animator.applyRootMotion = true; } else { Animator.applyRootMotion = false; }
Animator.applyRootMotion = true;
// Root motion applied every frame without optimization or culling| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Continuous root motion without culling | N/A | N/A | High CPU usage delays frame rendering | [X] Bad |
| Conditional root motion with visibility checks | N/A | N/A | Reduced CPU usage, smoother frames | [OK] Good |
applyRootMotion on an Animator component do in Unity?applyRootMotion to true allows the animation's movement data to move the character automatically.applyRootMotion to enable root motion.animator.applyRootMotion = true; is valid C# syntax and correct property usage.void OnAnimatorMove() {
Vector3 rootPos = animator.rootPosition;
rootPos.y = transform.position.y;
transform.position = rootPos;
}
What is the effect of this code on the character's movement?void OnAnimatorMove() {
transform.position = animator.rootPosition;
transform.rotation = animator.rootRotation;
}
But the character does not move as expected. What is the likely problem?applyRootMotion is true on the Animator component.OnAnimatorMove to override root motion is valid, but it requires applyRootMotion enabled.OnAnimatorMove to achieve this?OnAnimatorMove to set horizontal position from root motion and add vertical velocity manually to Y position.