Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved 2022.1.12f Playables API does not work

Discussion in 'Animation' started by sergiusz308, Aug 8, 2022.

  1. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    234
    Following Unity manual on setting up simple Playables API mixer it does not work: once in Play mode, animation is not playing, mixer does not react to changes to weight.

    Is there anything else I should setup?

    Steps:

    1. Import mixamo humanoid animations (walk, idle)
    2. Drag mixamo animation into the scene
    3. Add "Test_Playable" script to the newly created game object
    4. Setup references (animation clips)
    5. Hit play
    6. Nothing plays (animation on the character)

    Editor:

    Object Setup:

    upload_2022-8-8_10-43-45.png

    Hierarchy:
    upload_2022-8-8_10-44-24.png

    Code:
    Code (CSharp):
    1. public class Test_Playable : MonoBehaviour
    2.     {
    3.         [SerializeField] AnimationClip Clip1;
    4.         [SerializeField] AnimationClip Clip2;
    5.         [Range(0f, 1f)]
    6.         [SerializeField] float Ratio;
    7.  
    8.         private Animator a;
    9.  
    10.         private PlayableGraph graph;
    11.         private AnimationMixerPlayable mixer;
    12.         private AnimationPlayableOutput output;
    13.  
    14.         private void OnEnable()
    15.         {
    16.             if (this.a == null) { this.a = this.GetComponent<Animator>(); }
    17.             this.Initialize_Playable();
    18.  
    19.         }
    20.  
    21.         private void Initialize_Playable()
    22.         {
    23.             this.graph = PlayableGraph.Create();
    24.             this.graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
    25.  
    26.             AnimationClipPlayable ac1 = AnimationClipPlayable.Create(this.graph, this.Clip1);
    27.             AnimationClipPlayable ac2 = AnimationClipPlayable.Create(this.graph, this.Clip2);
    28.  
    29.             this.mixer = AnimationMixerPlayable.Create(this.graph, 2);
    30.  
    31.             this.mixer.ConnectInput(0, ac1, 0);
    32.             this.mixer.ConnectInput(1, ac2, 0);
    33.  
    34.             this.output = AnimationPlayableOutput.Create(this.graph, "test", this.a);
    35.  
    36.             this.output.SetSourcePlayable(this.mixer);
    37.             this.graph.Play();
    38.         }
    39.  
    40.         void Update()
    41.         {
    42.             this.mixer.SetInputWeight(0, this.Ratio);
    43.             this.mixer.SetInputWeight(1, 1 - this.Ratio);
    44.         }
    45.  
    46.         private void OnDestroy()
    47.         {
    48.             graph.Destroy();
    49.         }
    50.     }
     
  2. sergiusz308

    sergiusz308

    Joined:
    Aug 23, 2016
    Posts:
    234
    What worked for me is to fill out avatar field in the Animator, with a proper avatar for the humanoid rig.
    I wish it was mentioned in the docs in the first place...