Search Unity

How to know what transition condition is triggering in animator?

Discussion in 'Animation' started by AgathaPwned, May 16, 2018.

  1. AgathaPwned

    AgathaPwned

    Joined:
    Jan 16, 2018
    Posts:
    3
    Hello, I need to find a solution for a situation where there are multiple conditions in a transition and I need to know which one is triggering the transition.
    I'm not sure if this is shown somewhere or if this can be accomplished via editor extension.
    Thanks in advance
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    What have to tried so far?
    Is this some kind of action beat em up/fighting character controller?
     
  3. AgathaPwned

    AgathaPwned

    Joined:
    Jan 16, 2018
    Posts:
    3
    No, it's a 3D platformer, with many different animations for idle, run, and even jump.
    There are also some blend trees
     
  4. AgathaPwned

    AgathaPwned

    Joined:
    Jan 16, 2018
    Posts:
    3
    After some research, I have been able to get a print on the console of the condition that is triggering a transition (useful when having multiple conditions).
    At first I thought I would need an editor extension, but after a lot of struggling I realized I cold achieve this using a state behaviour.
    If you need it, just create a script like this and add it to a state behaviours, then change the parameter of IsUserName to the names you used for your transitions
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class behaviour : StateMachineBehaviour {
    4.  
    5.     //OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    6.     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
    7.         if(animator.GetAnimatorTransitionInfo(layerIndex).IsUserName("c")) Debug.Log("C!");
    8.         if(animator.GetAnimatorTransitionInfo(layerIndex).IsUserName("b")) Debug.Log("B!");
    9.         if(animator.GetAnimatorTransitionInfo(layerIndex).IsUserName("d")) Debug.Log("D!");
    10.     }
    11. }