Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

StateMachineBehaviours are not available after creating AnimatorControllerPlayable

Discussion in 'Timeline' started by dwit_mass_creation, Sep 12, 2017.

  1. dwit_mass_creation

    dwit_mass_creation

    Joined:
    Jun 18, 2015
    Posts:
    43
    I'm creating AnimatorControllerPlayable from AnimatorController. After entering playing mode, it is playing ok, but all StateMachineBehaviours in this AnimatorController disapear (and of course are not working).

    For normal Animator after entering Play Mode all StateMachineBehaviours are recreated as clones, but it is not working for AnimatorControllerPlayable.

    BUT when during Play Mode I add in Animator Window new StateMachineBehaviour to some state in AnimatorController it is added AND all other StateMachineBehaviours are initialized and working OK.

    Am I missing some initialization for AnimatorControllerPlayable?

    UPDATE: Animator.GetBehaviours<StateMachineBehaviour>() after creating PlayableGraph with AnimatorControllerPlayable returns correct amount of StateMachineBehaviours, so it looks like they are added but not initialized.
     
    Last edited: Sep 12, 2017
  2. dwit_mass_creation

    dwit_mass_creation

    Joined:
    Jun 18, 2015
    Posts:
    43
    Ok. I found my problem (I don't know if it is working as intended, but maybe solution will help someone).

    I was creating AnimatorControllerPlayable from RuntimeAnimatorController in Animator:

    Code (CSharp):
    1. Animator Anim;
    2. //creating PlayableGraph from AnimatorController
    3. InitAnimator(Anim.runtimeAnimatorController);
    4. //set AnimatorController to null because it messes with PlayableGraph
    5. Anim.runtimeAnimatorController = null;
    My solution is set controller to null before creating PlayableGraph and it's working:

    Code (CSharp):
    1. Animator Anim;
    2. RuntimeAnimatorController mainAnimator = Anim.runtimeAnimatorController;
    3. //set AnimatorController to null because it messes with PlayableGraph
    4. Anim.runtimeAnimatorController = null;
    5. //creating PlayableGraph from AnimatorController
    6. InitAnimator(mainAnimator);
    7.