Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to know what transition condition is triggering in animator?

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

  1. Amnesiac

    Amnesiac

    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,670
    What have to tried so far?
    Is this some kind of action beat em up/fighting character controller?
     
  3. Amnesiac

    Amnesiac

    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. Amnesiac

    Amnesiac

    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. }