Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. 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
  8. 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,772
    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. }