# UNITY || How to access the “exit transitions” of the current played clip from the animator?

So, I have an animator , i can access it. But from there I have no idea how to access the clips inside. I need to access the transition of the clips.

I got as far as accessing the object of the "Animator" class.

EDIT:

It appears The TransitionInfo datatype doesnt provide conditions. I need the conditions!

• Are you trying to access it via code or in the inspector? – aytimothy Dec 2 '18 at 5:30
• via code of course :) – OC_RaizW Dec 2 '18 at 11:32
• I'm curious why you need to access the transitions themselves. Can you describe what feature this is serving? There might be other ways to achieve your ultimate goal. – DMGregory Dec 7 '18 at 10:44
• @DMGregory: Its about the transition. You see, during the transition the animator is in 2 states at once. And setting the transition time to 0 doesnt help. He is always at least for a very short time in 2 states, which messes with "on state enter" and "on state leave"- since LEAVE is called before enter. – OC_RaizW Dec 10 '18 at 2:14
• Can you describe how this causes issues in your game? We might be able to find more straightforward solutions to those issues. – DMGregory Dec 10 '18 at 2:15

It's somewhat complicated but achievable. This is a list of things you'll need to go through:

1. Give the transition a name in the editor. Let's say you call it "AnimAToAnimB".

2. Figure out which layer of the animator the transition is in. Let's assume it's in the default "Base Layer".

3. Query the hash code of the transition up-front via code:

animator.StringToHash("Base Layer.AnimAToAnimB");

and store it in some variable, let's say transitionAToBHash.

4. Research "Animator State Machine Behaviours". You'll want one attached inside the layer of the transition that you're interested in.

6. Once you have your custom state behaviour attached and implemented, upon receiving the OnStateExit callback, grab the currently active animation transition and compare it to your cached transition hash:

// inside your custom state machine behaviour

override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
var transitionInfo = animator.GetAnimatorTransitionInfo(layerIdOfYourTransitionAToB);

{
// PROFIT! your transition "transitionAToB" has just started!
}
}


Note: it can get a lot more complicated if you're using things like sub state machines.

• sir youre awesome. I actually gave up a while ago... I thought its unachiveable since I read a 3-pages long forumpost about this particular problem. – OC_RaizW Dec 10 '18 at 2:12
• Whops... i have to take the "correct answer" back... I mean. Yeah i get the info, but i dont have access to those conditions inside that particular transition. – OC_RaizW Dec 10 '18 at 2:16
• Can you provide more details as to what do you mean by "I don't have access to those conditions"? – mt_ Dec 10 '18 at 16:25
• Allright, i updated my question – OC_RaizW Dec 11 '18 at 1:01
• In theory it's still doable, but the solution wouldn't be pretty nor very maintainable. You'd have to write an editor script that would grab your AnimatorController, walk all of it's transitions, as shown here: forum.unity.com/threads/find-all-animator-transitions.473779, access the conditions inside AnimatorState.transitions and then create a dictionary that would map transitionHash -> yourOwnConditionStruct and eventually pass that dictionary to a game object that's interested in knowing transition conditions. Also, you'd have to run this script every time transitions change. – mt_ Dec 11 '18 at 4:56

Use the below code to call the animation using script

public Animator Anim;
void Start(){
Anim.Play("Animation_Clip_Name");
}
//Trigger it by button click or inside other functions to change the animation.
public void NextAnimation()
{
Anim.Play("Next_Animation_Name");
}

• yeah thats not the question here – OC_RaizW Dec 10 '18 at 2:10