Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Change the animation motion at runtime

Discussion in 'Animation' started by orlandoarbert, Nov 13, 2023.

  1. orlandoarbert


    Sep 21, 2021
    I changes the motion at runtime with the following code:

    AnimatorStateMachine stateMachine = animatorController.layers[0].stateMachine;
    if (animation.animationBlendTree.Length > 0) {
    stateMachine.states[0].state.motion = animation.blendTree;
    } else {
    stateMachine.states[0].state.motion = animation.animationClip;

    animator.SetInteger("Anim", 5);

    but for some reason animator.SetInteger("Anim", 5); doesn't work. If I comment out the motion assignments, it works. What could be causing this? Is this normal?