Search Unity

Mecanim calling StateMachineBehaviour script on empty state

Discussion in 'Animation' started by Noktai, Jun 1, 2015.

  1. Noktai

    Noktai

    Joined:
    Feb 11, 2013
    Posts:
    40
    I'm having a very strange issue with my statemachine.

    I have a StateMachineBehaviour to play spine animations (3rd party animation software).
    I noticed that empty states with no behaviours attached would reset the animation.



    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlaySpineAnimSB : StateMachineBehaviour {
    5.  
    6.     public string animation;
    7.     private SkeletonAnimation skeletonAnim;
    8.  
    9.     // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    10.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    11.  
    12.         if( skeletonAnim == null ) skeletonAnim = animator.gameObject.GetComponent<SkeletonAnimation>();
    13.         skeletonAnim.skeleton.SetBonesToSetupPose();
    14.         skeletonAnim.AnimationName = animation;
    15.  
    16.         string currentState = "";
    17.         if( stateInfo.IsName( "Idle" ) ) currentState = "Idle";
    18.         else if( stateInfo.IsName( "Run" ) ) currentState = "Run";
    19.         else if( stateInfo.IsName( "New State" ) ) currentState = "New State";
    20.         else if( stateInfo.IsName( "Empty" ) ) currentState = "Empty";
    21.  
    22.         Debug.Log( "entered state: " + currentState + " and play animation : " + animation  );
    23.     }
    24. }
    Now I have removed statemachinebehaviours everywhere, but somehow the code is still being called.
    Here's a small part of my log.



    I am absolutely clueless as to why this happening. Any help?