Search Unity

Learning Playable API

Discussion in 'Animation' started by JaviTheGreat, Apr 15, 2020.

  1. JaviTheGreat

    JaviTheGreat

    Joined:
    Sep 28, 2015
    Posts:
    6
    Hi community!

    I think the Playable API is very interesting and I see its benefits. So I've been reading the available documentation and examples. I really want to learn more about it.

    I have some questions about how to implement specific AnimatorController logic, using Playables API.

    This is what the AnimatorController looks like (See attached image in case link is lost):


    AnimatorController description:
    • There are 5 states: A, B, A2B, B2A and C
    • Default is A, and it has a StateMachineBehaviour that, every loop, chooses randomly between 3 events:
      1. Loop A with 20% chance.
        This option just replays A and evaluates the random choice again.
      2. Go to A2B with 30% chance.
        This option plays in order the states A2B -> B -> B2A -> A. Then A evaluates the random choice again. Note that every transition between these states has 10% of blend from one to the other.
      3. Go to C with 50% chance.
        This option executes C, which has a BlendTree with 5 animations. It also has a StateMachineBehaviour that randomly chooses the animation to play by setting the blending tree parameter. Then it goes back to A.
    It is hard for me to see the Playable Graph tree that executes this logic. In particular I wonder:
    • How to make those kind of transitions (A->A2B->B->B2A-A) with the 10% of blending. In the examples I've seen only parallel blending with BlendTrees. But this is sequential blending.
    • How those StateMachineBehaviours translate into ScriptPlayables in terms of architecture. I mean, should I attach an AnimatorMonoBahaviour to the GameObject/Player that uses all those ScriptPlayables attached to nodes. And trigger them according to logic? or only create them when needed? What is the best architecture here?
    • In general, how a transitions between states translate into transitions between graph nodes?
    • Is a graph for this possible? Should it be created once at the beginning? or should it be created dynamically?
    If someone could help me translate this AnimatorController into Playables it would be really helpfull.

    Thanks!
     

    Attached Files:

  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Playables do not execute logic in the same way as Animator Controllers, you have to tell them what to do with scripts. Transitioning between animations over time is done with mixers just like Blend Trees, you simply change the weights every frame to fade one animation in and the others out.

    They don't have any equivalent to StateMachineBehaviours with entry and exit events either. It's entirely up to you to implement all the necessary logic in your scripts.

    Playables give the flexibility you need if you want to make an animation system from scratch, but they are not easily usable as an animation system out of the box. I would recommend you instead check out Animancer (link in my signature) which has transitions and a state machine system already implemented. It has lots of examples, including one about deconstructing an Animator Controller to use Animancer and some about using Animator Controllers alongside separate Animation Clips if you want to try a hybrid approach.
     
  3. JaviTheGreat

    JaviTheGreat

    Joined:
    Sep 28, 2015
    Posts:
    6
    @Kybernetik thank you for your answer

    That is exactly what I was writing about... In the mixer examples I saw they blend only in parallel, not in sequence. For example:
    If you mix clip A and clip B, starting from A.weight=1f and B.weight=0f
    Then, if in the middle you change to A.weight=0f and B.weight=1f
    The end result will be: Play first half of A and second half of B, because A and B are running in parallel.

    I don't want that. What I'm looking for is to blend the end of A with the beginning of B (in sequence).
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Yeah, so you just change the weights every frame to gradually move towards the values you want.