Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. 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,781
    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. }