- Home /
Transition to multiple states from Entry Node in Unity 5
I'm trying to create a simple 2d animator where the direction the sprite faces when a scene loads (ie. Right, Left, Up, etc.) depends on the direction the sprite faced in the previous scene.
I followed the tutorial here and created a sub-state machine with just 2 states, facing right and facing left. I made the "facing right" state the default, and added a transition from Entry Node to the "facing left" state with the condition that direction = 1.
Then, I added a behavior to this sub-state machine with the following line:
override public void OnStateMachineEnter(Animator animator, int stateMachinePathHash){
animator.SetInteger ("direction", 1);
}
However, when I hit play, the animator still goes to the default right state. I've tried a bunch of things but it seems like I cannot get it to do anything beside the default transition from Entry. The fact that I cannot find an answer to this question online makes me feel like I missed something completely obvious, but for the life of me I cannot figure it out.
Answer by kyram · Oct 07, 2015 at 05:51 PM
This solution doesn't solve the Entry Node only using the default transition, but I was able to solve my particular problem using blend trees. In my case I had a blend tree named "Idle" (the default state) and a blend tree named "Run". In each blend tree I used a float parameter to control which idle and which run animation to play (ie. left or up or right). It works for 2d animation because I'm not using the blending feature. I would never need to set the float parameter to be midway between two thresholds.
But if anyone has any thoughts about the entry node only using default transition, please share!